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

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
   
   
   
   
1 2 3 4 5
 
Sample Output
   
   
   
   
0 1 2 1 3

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"); 
		else
		cout<<a[n]<<endl;
	}
    return 0;	
}


你可能感兴趣的:(HDU,Prime,factor,Largest,2136,素数筛选+打表)