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).
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.
OutputOutput the LPF(n).
Sample Input
1 2 3 4 5Sample Output
0 1 2 1 3
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
#define LL long long
const int MAX = 1e6+10;
const int INF = 0x3fffffff;
int a[MAX];
int id[MAX];
void init(){//素数打表,用id数组记录素数的排名序号
memset(a,0,sizeof(a));
memset(id,0,sizeof(id));
for(int i=2;i<=MAX;i++){
for(int j=2;i*j<=MAX;j++){
if(!a[i]){
a[i*j]=1;
}
}
}
int num=0;
a[0]=0;a[1]=0;
id[0]=0;id[1]=0;
for(int i=2;i<=MAX;i++){
if(!a[i]){
num++;
}
id[i] = num;
}
}
int LPF(int n){
int temp;
for(int i = 2;i*i <= n;i++){//因式分解
if(n%i==0){
temp = i;
while(n%i==0){
n /= i;
}
}
}
//找到最大的质数
if(n==1) return id[temp];
else return id[n];
}
int main(){
init();
int n;
while(scanf("%d",&n)!=EOF){
if(n==1) printf("0\n");
else {
int ans = LPF (n);
printf("%d\n",ans);
}
}
return 0;
}