| ||||||||||
| 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 | |||||||||
Re:怎样减少运行时间? 看来只能先建立一个素数表,用内存换时间了……In Reply To:怎样减少运行时间? 看来只能先建立一个素数表,用内存换时间了…… Posted by:visual at 2006-04-21 19:04:51 这是我的代码,Sample没过,照样也敢交。然后OJ给了个Rumtime Error。
本来是不敢交的,看到楼下xfxyjwy兄的代码中开了个number[1000001]的数组,才鼓起勇气交上去的。
弄不明白了,难道xfxyjwy兄开了这么大的数组却能过吗?
#include<stdio.h>
#define N 1000001
bool number[N]={0};
void compute_prime()
{
int i,j;
for(i=2;i<N;i++)
if(number[i]==0)
for(j=i;i*j<N;j++)
number[i*j]=true;
}
int main()
{
int n,i;
compute_prime();
while(scanf("%d",&n))
{
if(n==0) break;
for(i=2;i<N;i++)
if(!number[i] && !number[n-i])
{
printf("%d = %d + %d\n",n,i,n-i);
break;
}
}
return 0;
}
Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator