博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
[暑假集训--数论]hdu2136 Largest prime factor
阅读量:4678 次
发布时间:2019-06-09

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

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. 

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

OutputOutput the LPF(n). 
Sample Input

12345

Sample Output

01213

 

对x分解质因数,问最大的质因子是第几大质数

瞎暴力就好

1 #include
2 #include
3 #define LL long long 4 using namespace std; 5 inline LL read() 6 { 7 LL x=0,f=1;char ch=getchar(); 8 while(ch<'0'||ch>'9'){
if(ch=='-')f=-1;ch=getchar();} 9 while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}10 return x*f;11 }12 int mk[1000010];13 int pp[300010],len;14 int rnk[1000010];15 int n;16 inline void getp()17 {18 for (int i=2;i<=1000000;i++)19 {20 if (!mk[i])21 {22 for (int j=2*i;j<=1000000;j+=i)mk[j]=1;23 pp[++len]=i;24 rnk[i]=len;25 }26 }27 }28 int main()29 {30 getp();31 while (~scanf("%d",&n))32 {33 if (!mk[n]){printf("%d\n",rnk[n]);continue;}34 int mx=0;35 for (int i=1;i<=len;i++)36 {37 if (pp[i]*pp[i]>n)break;38 if (n%pp[i]==0)mx=i;39 while (n%pp[i]==0)n/=pp[i];40 }41 if (n!=1)mx=rnk[n];42 printf("%d\n",mx);43 }44 }
hdu 2136

 

转载于:https://www.cnblogs.com/zhber/p/7285547.html

你可能感兴趣的文章
How to show only next line after the matched one?
查看>>
手续费
查看>>
yii2框架随笔19
查看>>
为什么要使用getter/setter
查看>>
使用7zip把jre集成到绿色运行程序内
查看>>
07_Python的控制判断循环语句1(if判断for循环)_Python编程之路
查看>>
15_Python模块化编程_Python编程之路
查看>>
【leetcode 简单】第十七题 x 的平方根
查看>>
cocos2d-x 3.1 编译脚本android-build.py
查看>>
Java web servers 间是如何实现 session 同步的
查看>>
HDU 6319(单调队列)
查看>>
Codeforces 1041C(贪心+set)
查看>>
Android 常用数据操作封装类案例
查看>>
php方法 隐藏手机号中间四位
查看>>
程序员技术练级攻略
查看>>
Binary Agents
查看>>
需求获取常见的方法是进行客户访谈,结合你的实践谈谈会遇到什么问题,你是怎么解决的?...
查看>>
django之同源策略
查看>>
org.springframework.beans.factory.BeanCreationException...
查看>>
大量文本框非空判断,如何提高灵活性?
查看>>