#cin和cout造成的超时(Time Limit Exceeded)

#问题来源于HDOJ2136 

#原题:

Largest prime factor

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


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
 
  
12345
 

Sample Output
 
  
01213
 

#AC码:

//#include<iostream>
#include<stdio.h>
#include<string.h>
//using namespace std;
#define max 1000000
int num[max];

void perp()
{
    int cn=1;
    for(int i=2;i<max;i++)
        if(num[i]==0)
        {
            for(int j=1;j*i<max;j++)
            num[j*i]=cn;
            cn++;
        }
}
int main()
{
    memset(num,0,sizeof(num));
    int n;
    perp();
    while(scanf("%d",&n)!=EOF)
        printf("%d\n",num[n]);

}

#问题:如果将scanf和printf换成cin和cout,则Time Limit Exceeded

#原因分析:(查找到相关博客点击打开链接

仅仅IO速度差别!

以后在大量IO时一定要注意这点。

猜你喜欢

转载自blog.csdn.net/u014302425/article/details/80488723