[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 ...
随机推荐
- ASP.NET动态加载用户控件的方法
方法是使用LoadControl方法,根据用户控件的相对路径,动态生成用户控件对象 用户控件 public class UserControlA :UserControl { public UserC ...
- GDI学习之俄罗斯方块续
当前方块对象 #region 定义砖块int[i,j,y,x] Tricks:i为那块砖,j为状态,y为列,x为行 private int[, , ,] Tricks = {{ { {,,,}, {, ...
- 什么是purge操作
要明白什么清空(purge)操作,你得明白什么是事务的多版本控制,即MVCC(multi-version concurrency control).Innodb为了实现MVCC, 需要在表空间内保存老 ...
- Spring-framework下载
下载版本,修改版本号就行. http://repo.springsource.org/libs-release-local/org/springframework/spring/4.3.2.RELEA ...
- ubuntu16.04服务器配置ssh免密登录
原版资料英文,链接在此 https://www.digitalocean.com/community/tutorials/how-to-set-up-ssh-keys--2 在客户端操作 ssh-k ...
- 一·创建Linux服务器(基于阿里云)
本系统是基于阿里云服务器,购买请前往https://www.aliyun.com/?spm=5176.8142029.388261.1.taXish ,由于经济能力的限制,本人购买的是最低配置如下 其 ...
- Linux系统之压缩、解压缩,vi编辑器,系统初始化服务和系统监控
一.正文处理,压缩与解压缩 1.内容重定向>与>> >:覆盖,将>号左边的结果覆盖到>号右边的文件中,如果文件不存在,则先创建一个新的空文件并覆盖 >> ...
- centos6.7 安装Docker
一.查看系统版本 [root@localhost ~]# cat /etc/redhat-release CentOS release 6.7 (Final) 二.安装EPEL 1.进入cento ...
- 【转载】kafka的工作原理
http://www.ibm.com/developerworks/cn/opensource/os-cn-kafka/index.html 消息队列 消息队列技术是分布式应用间交换信息的一种技术.消 ...
- 基于元数据的ETL系统
从努力到选择 从实现到设计 从部分到整体 以下是我对DW design的一些想法 下次使用C#来实现一下 ETL中Source 的信息 数据提供形式:DB(ORACLE SQLSE ...