如何解决TimeOut问题.. [英] How to solve TimeOut problem..
本文介绍了如何解决TimeOut问题..的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当我执行这个程序时,我会超时。
如何解决这个问题,我想先打印10,000个素数?
提前谢谢....
我的代码是
void main()
{
int i,j; int count;
for (i = 2 ; i< 100000; i ++)
{count = 0 ;
for (j = 2 ; j< = sqrt(i); j ++)
{
if (i%j == 0 )
++计数;
}
if (count == 0 )
printf( %d \ n,i);
}
}
解决方案
您的程序在我的系统(WinXP)上正常运行。您的系统是否有稀缺资源?
请注意:有更聪明的方法来计算素数(例如,参见维基百科的Generating Primes[ ^ ]。
When I am executing this program iam getting timeout.
How to solve this problem and I want to print first 10,000 primes?
Thanks in advance....
my code is
void main()
{
int i,j; int count;
for(i=2;i<100000;i++)
{ count=0;
for(j=2;j<=sqrt(i);j++)
{
if(i%j==0)
++count;
}
if(count==0)
printf("%d\n",i);
}
}
解决方案
You program runs fine on my system (WinXP). Has your system scarce resources?
Please note: there a more clever ways for computing prime numbers (see, for instance "Generating Primes" at Wikipedia[^].
这篇关于如何解决TimeOut问题..的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文