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,所有的数据都过了出来出现负数(附code)#include<stdio.h> #include<iostream> using namespace std; void sum(__int64 n,bool prime[]) { __int64 k=2; memset(prime,0,(n+10)*sizeof(bool)); while(k<=n) { for(__int64 i=2*k;i<=n;i+=k) prime[i]=1; while(1) { k++; if(prime[k]==0) { break; } } } } int main() { bool prime[1000016]={1,1,0}; __int64 a,b; __int64 num1,num2; prime[0]=prime[1]=1; prime[2]=0; while(1) { scanf("%I64d%I64d",&a,&b); if(a==b && b==-1) break; num1=num2=0; sum(b,prime); for(__int64 i=a;i<=b;i++) { if(prime[i]==0) { num1++; if((i-1)%4==0) num2++; } } printf("%I64d %I64d %I64d %I64d\n",a,b,num1,num2); } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator