Largest prime factor
Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 11075 Accepted Submission(s): 3907
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
题意:给你一个数 n ,输出组成这个素数的最大的素数在素数表中的位置(2,3,5,7......依次位置是:1,2,3,4,.....)
题解:看代码,很好理解
#include<cstdio>
int a[1000000];
void init()
{
int k=1; //位置从1开始
for(int i=2;i<1000000;i++)
{
if(!a[i])
{
a[i]=k;
for(int j=i*2;j<1000000;j+=i)
a[j]=k;
k++;
}
}
}
int main()
{
init();
long long n;
while(~scanf("%lld",&n))
printf("%d\n",a[n]);
return 0;
}
本篇介绍了一个算法挑战,任务是确定任意给定正整数的最大素因数在其素数序列中的位置。通过使用预先计算的素数筛法,能够快速找到每个数的最大素因数,并给出其在素数表中的位置。
&spm=1001.2101.3001.5002&articleId=52853256&d=1&t=3&u=9e24b73e75dd4bea94c23e35d1a55b24)
1386

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



