博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Largest prime factor
阅读量:2242 次
发布时间:2019-05-09

本文共 1028 字,大约阅读时间需要 3 分钟。

Largest prime factor

Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) 
Total Submission(s): 6803 Accepted Submission(s): 2078

Problem Description 
Everybody knows any number can be combined by the prime number. 
Now, your task is telling me what position of the largest prime factor. 
The position of prime 2 is 1, prime 3 is 2, and prime 5 is 3, etc. 
Specially, LPF(1) = 0.

Input 
Each line will contain one integer n(0 < n < 1000000).

Output 
Output the LPF(n).

Sample Input 




5

Sample Output 




3

题目大意求num的最大质因数是在素数表里的排名,本来以为自己的很优化了,结果别人直接用筛选法,把所有数的最大质因数放到相应的数组里。惭愧惭愧!!!

//最大质因数 #include 
using namespace std; const int maxn = 1000000+5; int a[maxn]; int main() { int ans = 0; for (int i = 2; i < maxn; i++) { if (!a[i]) { ans++; for (int j = i; j < maxn; j += i) a[j] = ans; } } int n; while(scanf("%d",&n) == 1) { printf("%d\n",a[n]); } return 0; }

转载地址:http://xtgbb.baihongyu.com/

你可能感兴趣的文章
如何理解MVC模型
查看>>
SpringMVC中乱码解决方案
查看>>
SpringMVC中时间格式转换的解决方案
查看>>
post和get请求相关知识点
查看>>
关于try finally 中的return语句的问题
查看>>
RequestBody/ResponseBody处理Json数据
查看>>
springmvc请求参数获取的几种方法
查看>>
在eclipse中创建和myeclipse一样的包结构
查看>>
Java中的IO流
查看>>
java中的关键字
查看>>
如果某个方法是静态的,它的行为就不具有多态性
查看>>
优化Hibernate所鼓励的7大措施
查看>>
Java 8系列之重新认识HashMap
查看>>
HashMap 、 ArrayList、String 重写了equals方法 而Object类(比如User)没有重写
查看>>
Servlet的生命周期
查看>>
Object中的getClass()返回的是当前运行的类
查看>>
加载驱动程序的方法
查看>>
深入理解java异常处理机制
查看>>
object类的基本方法
查看>>
回答阿里社招面试如何准备,顺便谈谈对于Java程序猿学习当中各个阶段的建议
查看>>