HDU:2136 Largest prime factor!(素数)

来源:互联网 发布:淘宝二手商品3c认证 编辑:程序博客网 时间:2024/04/20 09:30

Largest prime factor

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


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
12345
 

Sample Output
01213
 

Author
Wiskey
 

Source
HDU 2007-11 Programming Contest_WarmUp
 

Recommend

威士忌


题目大意:我们知道,每个数都能拆分成素数的乘积的形式,给你一个数字n,问你组成这个数字的素数中最大的素数是谁?输出这个素数的位置。(其中素数2对应的位置为1,素数3对应的位置为2,素数5对应的位置为3,特别的1(虽然不是素数)对应的位置为0.)


解题思路:筛素法。


代码如下:

#include <cstdio>int a[1000010];void dabiao(){a[1]=0;int k=1;for(int i=2;i<1000010;i++){if(a[i]!=0){continue;}a[i]=k;for(int j=i*2;j<1000010;j=j+i){a[j]=k;}k++;}}int main(){dabiao();int n;while(scanf("%d",&n)!=EOF){printf("%d\n",a[n]);}return 0;} 



0 0
原创粉丝点击