Largest prime factor
Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 11191 Accepted Submission(s): 3961
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.
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
Recommend
威士忌
#include<cstdio>
#include<iostream>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
const int MAXN = 1000010;
int vis[MAXN];
void getvis() {
int k=1;
for(int i=2; i<=MAXN; i++) {
if(!vis[i]) {
vis[i]=k;
for(int j=i+i; j<=MAXN; j+=i) {
vis[j]=k;
}
k++;
}
}
}
int main() {
getvis();
int n;
while(scanf("%d",&n)!=EOF) {
printf("%d\n",vis[n]);
}
return 0;
}

本文介绍了一种通过打表法快速求解任意整数的最大质因数在其质数序列中位置的算法,并提供了一个完整的C++实现示例。
758

被折叠的 条评论
为什么被折叠?



