[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 ...
随机推荐
- opencms忘记Admin用户登录密码解决方案
不知道现在还有多少人在用opencms: 我今天就是遇到一个问题,很久之前部署的一台opencms服务器,突然忘记密码了,记录下处理方法: 希望对你有帮助: opencms忘记Admin用户登录密码了 ...
- 管理故事——和尚挑水的故事
有时候企业.公司的各种混乱都是源于管理问题,例如人浮于事.资源错配.机构臃肿-----,暂且不说企业管理.项目的管理,光是个人工作的管理.一个处理不好,接踵而来的就是一堆问题,可怕的不是出现问题,而是 ...
- JQuery异步提交
JQuery提交部分 $.ajax({ url:'www.baidu.com', //提交的地址,相当于form的action type:'POST', //提交方式,相当于form的method d ...
- tomcat 部署脚本
将一下3个脚本放到一个目录里,做成一个 python 的包即可使用 脚本介绍 操作服务脚本 #!/usr/bin/env python # _*_coding:utf-8_*_ # Author: & ...
- 计算1到最大的n位十进制数 ——大数解决
要求:输入一个数字n,按照顺序打印出从1到最大的n为十进制.比如输入3,则打印出1.2.3……一直到最大的3位数999 这个看起来好像很简单啊.巴拉巴拉,已经得出了下面的代码 /** * 注意: 错误 ...
- jmeter的使用(四)
jmeter如何调用java程序呢,下面做简单介绍.1.打开eclipse,新建项目,导入jmeter依赖的包ApacheJMeter_core.jar和ApacheJMeter_java.jar,这 ...
- 边工作边刷题:70天一遍leetcode: day 88
Unique Word Abbreviation 要点: 简单题,主要是理解题意.no other words have the same abbreviation as the given word ...
- Codeforces Round 261 Div.2 E Pashmak and Graph --DAG上的DP
题意:n个点,m条边,每条边有一个权值,找一条边数最多的边权严格递增的路径,输出路径长度. 解法:先将边权从小到大排序,然后从大到小遍历,dp[u]表示从u出发能够构成的严格递增路径的最大长度. dp ...
- 类似区间计数的种类并查集两题--HDU 3038 & POJ 1733
1.POJ 1733 Parity game Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 5744 Accepted: ...
- Android外部SD卡的读取
package com.kevin.writeorreadfile1_1; import android.app.Activity; import android.bluetooth.le.ScanF ...