| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
同样是素数筛法,为什么我的266ms,心痛!哪位大侠能把我看看哪里可以节约时间吗?#include <stdio.h>
#include <stdlib.h>
int tab[1000000];
int main()
{
int a,d,n,i,j;
tab[0]=0;tab[1]=0;
for(i=2;i<1000000;i++)
tab[i]=1;
for(i=2;i<=1000000;i++)
{
if(tab[i] == 1)
{
for(j=2;j*i<1000000; j++)
{
tab[i*j]= 0;
}
}
}
while(scanf("%d %d %d",&a,&d,&n) != EOF && n)
{
int cout=0;
for(i=0;cout!=n;i++)
{
if(tab[a+i*d] == 1)
cout++;
}
printf("%d\n",a+(i-1)*d);
}
return 0;
}
Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator