HDU 2136 Largest prime factor(素数筛选+打表)

来源:互联网 发布:浙江师范行知学院qq群 编辑:程序博客网 时间:2024/04/28 04:39

Largest prime factor

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

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

AC代码:
#include<iostream>  #include<memory.h>  #include<cstdlib>  #include<cstdio>  #include<cmath>  #include<cstring>  #include<string>  #include<cstdlib>  #include<iomanip>  #include<vector>  #include<list>  #include<map>  #include<algorithm>  typedef long long LL;  using namespace std; const LL maxn=1e6;const LL mod=10000000; int a[maxn]={0};//素数筛选:打表 int main(){int n,k=1;for(int i=2;i<maxn;i++){if(a[i]==0){a[i]=k++; //position for(int j=i+i;j<maxn;j+=i){a[j]=a[i]; }}}while(~scanf("%d",&n)){if(n==1)printf("0\n"); elsecout<<a[n]<<endl;}    return 0;}


1 0
原创粉丝点击