[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 ...
随机推荐
- animation of android (2)
android Interpolator 首先是android系统提供的变换方式: 这些方式将转载一篇文章: 转: http://www.cnblogs.com/mengdd/p/3346003.ht ...
- APACHE重写去除入口文件index.php
下面我说下 apache 下 ,如何 去掉URL 里面的 index.php 例如: 你原来的路径是: localhost/index.php/index 改变后的路径是: localhost/ind ...
- [分享]一个String工具类,也许你的项目中会用得到
每次做项目都会遇到字符串的处理,每次都会去写一个StringUtil,完成一些功能. 但其实每次要的功能都差不多: 1.判断类(包括NULL和空串.是否是空白字符串等) 2.默认值 3.去空白(tri ...
- 详解apache的allow和deny
今天看了一篇关于apache allow,deny的文章收获匪浅,防止被删,我直接摘过来了,原文地址!!! !http://www.cnblogs.com/top5/archive/2009/09/2 ...
- PAC学习框架
PAC学习框架是机器学习的基础.它主要用来回答以下几个问题: 什么问题是可以高效学习的? 什么问题本质上就难以学习? 需要多少实例才能完成学习? 是否存在一个通用的学习模型? PAC=probably ...
- MIT jos 6.828 Fall 2014 训练记录(lab 3)
注:源代码参见我的github: https://github.com/YaoZengzeng/jos Part A : User Environments and Exception Handlin ...
- 【ASP.NET 基础】表单和控件
1.HTML表单的提交方式 对于一个普通HTML表单来说,它有两个重要的属性:action 和 method.action属性指明当前表单提交之后由哪个程序来处理,这个处理程序可以是任何动态网页或者 ...
- 平摊分析 Amortized Analysis ------geeksforgeeks翻译
当偶尔一切操作很花的时间很慢,而大多数操作的时间都很快的时候,平摊分析的方法就很很好用了.在平摊分析中,我们分析一串操作并且可以得到最坏情况下的平均时间复杂度.例如hash table, disjoi ...
- C和指针笔记 3.7 存储类型
变量的破碎类型是指存储变量值的内存类型.变量的存储类型决定变量何时创建.何时销毁以及它的值将保持多久. 有三个地方可以用于存在变量:普通内存.运行时堆栈.硬件寄存器. 变量的缺省存储类型取决于它的声明 ...
- C# Thread.Join()用法的理解 转
指在一线程里面调用另一线程join方法时,表示将本线程阻塞直至另一线程终止时再执行 比如 1using System; 2 3namespace TestThreadJoin 4{ 5 class P ...