HDU 2136 Largest prime factor (最大素因子序号,cin超时呀!!!)

Largest prime factor

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


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
HDU 2007-11 Programming Contest_WarmUp

原题链接:http://acm.hdu.edu.cn/showproblem.php?pid=2136

题意:求最大素因子的序号,素数序号即为在素数表中的位置,例如:第1个为 2 ,第2个为 3 ,第 3 个为 5,
特别规定:第 0 个为 1.
用了素数筛选法还是超时,网上查看别人的代码,几乎一模一样,最后发现,别人用的是scanf(),printf(),而我用的是cin,cout,一改,便A了.

AC代码:

#include 
#include 
using namespace std;
#define maxn 1000000+5
int a[maxn];
int main()
{
    int ans=0;
    for(int i=2;i


你可能感兴趣的:(HDU,ACM_数论,ACM_数论_素数和因数分解,ACM_HDU刷题录)