[CareerCup] 7.7 The Number with Only Prime Factors 只有质数因子的数字
7.7 Design an algorithm to find the kth number such that the only prime factors are 3,5, and 7.
这道题跟之前LeetCode的那道Ugly Number II 丑陋数之二基本没有啥区别,具体讲解可参见那篇,代码如下:
class Solution {
public:
int getKthMagicNumber(int k) {
vector<int> res(, );
int i3 = , i5 = , i7 = ;
while (res.size() < k) {
int m3 = res[i3] * , m5 = res[i5] * , m7 = res[i7] * ;
int mn = min(m3, min(m5, m7));
if (mn == m3) ++i3;
if (mn == m5) ++i5;
if (mn == m7) ++i7;
res.push_back(mn);
}
return res.back();
}
};
[CareerCup] 7.7 The Number with Only Prime Factors 只有质数因子的数字的更多相关文章
- PAT-1059 Prime Factors (素数因子)
1059. Prime Factors Given any positive integer N, you are supposed to find all of its prime factors, ...
- 1059. Prime Factors (25)
时间限制 50 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 HE, Qinming Given any positive integer N, y ...
- PAT 1059. Prime Factors (25) 质因子分解
题目链接 http://www.patest.cn/contests/pat-a-practise/1059 Given any positive integer N, you are suppose ...
- 2014辽宁ACM省赛 Prime Factors
问题 L: Prime Factors 时间限制: 1 Sec 内存限制: 128 MB [提交][状态][论坛] 题目描写叙述 I'll give you a number , please te ...
- PAT1059:Prime Factors
1059. Prime Factors (25) 时间限制 100 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 HE, Qinming Given ...
- A1059. Prime Factors
Given any positive integer N, you are supposed to find all of its prime factors, and write them in t ...
- PAT 甲级 1059 Prime Factors
https://pintia.cn/problem-sets/994805342720868352/problems/994805415005503488 Given any positive int ...
- (笔试题)质数因子Prime Factor
题目: Given any positive integer N, you are supposed to find all of its prime factors, and write them ...
- PAT 1059 Prime Factors[难]
1059 Prime Factors (25 分) Given any positive integer N, you are supposed to find all of its prime fa ...
随机推荐
- AOP这些应用场景(交叉业务)
1.统计某个方法的性能,可以在每个业务方法执行前后 记录方法执行的当前时间,执行后的时间-执行前的时间= 方法执行时间. 这样就可以在开发过程中(项目未交付给客户前)统计程序的性能. 2.安全 ,权 ...
- dd 生成指定大小文件
d命令可以轻易实现创建指定大小的文件,如 dd if=/dev/zero of=test bs=1M count=1000 会生成一个1000M的test文件,文件内容为全0(因从/dev/zero中 ...
- Web Farm 和Web Garden
这两个都是提高网站性能的服务器端技术 1.Web Farm:如果应用程序被多个服务器托管,这种情况就可以称作Web Farm. 2.Web Garden: 指的是一个应用程序可以分成多个进程(w3wp ...
- linux下批量修改存有超大数据量IP文件中的IP内容以及去重排序
作为一个linux的学徒,分享一下自己解决这个小问题的心得,在处理这个问题时使用了一个小技巧感觉很适用,个人发觉linux的终端真滴是非常强大,下面就详细地介绍这个问题以及解决办法吧 问题描述:由于要 ...
- IE11的API变化
IE11已经登录Win8.1,它的API有了很大变更 一.User-agent字符串的更改 IE10的是 Mozilla/5.0 (compatible; MSIE 10.0; Windows NT ...
- PAT之我要通过
题目描述 “答案正确”是自动判题系统给出的最令人欢喜的回复.本题属于PAT的“答案正确”大派送 —— 只要读入的字符串满足下列条件,系统就输 出“答案正确”,否则输出“答案错误”. 得到“答案正确”的 ...
- 使用jmx监控tomcat
1.在tomcat启动过程中,开启相应的参数配置: -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=9999 -D ...
- Java之美[从菜鸟到高手演变]之JVM内存管理及垃圾回收
很多Java面试的时候,都会问到有关Java垃圾回收的问题,提到垃圾回收肯定要涉及到JVM内存管理机制,Java语言的执行效率一直被C.C++程序员所嘲笑,其实,事实就是这样,Java在执行效率方面确 ...
- sqlite查询结果在listview中展示
1.获取db实例 SQLiteDatabase db=dbhelper.getWritableDatabase(); 2.Cursord对象获取查询结构 Cursor cursor=db.rawQue ...
- codeforces 709D D. Recover the String(构造)
题目链接: D. Recover the String time limit per test 1 second memory limit per test 256 megabytes input s ...