丑数

设计一个算法,找出只含素因子357 的第 k大的数。

符合条件的数如:3,5,7,9,15......

您在真实的面试中是否遇到过这个题?

Yes
样例

如果k=4, 返回 9

挑战

要求时间复杂度为O(nlogn)或者O(n)

 import java.util.Queue;
import java.util.LinkedList; class Solution {
/**
* @param k: The number k.
* @return: The kth prime number as description.
*/
public long kthPrimeNumber(int k) {
long[] relust = new long[k];
relust[0] = 3;
relust[1] = 5;
relust[2] = 7;
int a = 0;
int b = 0;
int c = 0; for (int i=3;i<k ;i++ ) {
long temp = judge(relust[a]*3,relust[b]*5,relust[c]*7);
relust[i] = temp;
while(relust[a]*3 <= temp)a++;
while(relust[b]*5 <= temp)b++;
while(relust[c]*7 <= temp)c++;
} return relust[k-1];
}
public long judge(long a,long b,long c) {
long min = Math.min(a,b);
min = Math.min(min,c);
return min;
}
};

最新文章

  1. PHP基础知识之常量
  2. Windows简单几步实现系统自动关机设置
  3. Linux C 文件输入输出函数 fopen()、getc()/fgetc()、putc()/fputc()、fclose()、fprintf()、fscanf()、fgets()、fputs()、fseek()、ftell()、fgetpos()、fsetpos() 详解
  4. Android应用开发-数据存储和界面展现(一)(重制版)
  5. Python的第四天
  6. 远程桌面不能连接,提示awgina.dll取代错误的解决办法
  7. a与a:link、a:visited、a:hover、a:active
  8. 【POJ】2318 TOYS(计算几何基础+暴力)
  9. 根据headerView位置改变headerView颜色(collectionView/tableview)
  10. OpenCV学习 2:播放AVI视频
  11. Python:2D画图库matplotlib学习总结
  12. mysql 千万量级的表的优化
  13. 【算法系列学习】Dijkstra求最短路 [kuangbin带你飞]专题四 最短路练习 D - Silver Cow Party
  14. linux设备驱动之字符设备驱动模型(2)
  15. select * 和 select 所有字段的区别
  16. python 11
  17. springboot调优
  18. centos 7.5安装docker-CE 18
  19. 2018下半年Android面试历程
  20. JS笔记—01

热门文章

  1. ICPC2017 Urumqi - K - Sum of the Line
  2. python基础--结构篇
  3. How GitLab uses Unicorn and unicorn-worker-killer
  4. C# 生成系统唯一号
  5. Chrome profile manager
  6. 基本控件文档-UIButton属性---iOS-Apple苹果官方文档翻译
  7. jQuery操作Table学习总结[转]
  8. java 错误: 找不到或无法加载主类解决方法
  9. typeof的用法
  10. url编码模块