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 |
超级菜鸟,迫求高手,帮忙看看!why Runtime Error(急)#include<iostream> #include<cmath> using namespace std; int checkp(int num) { int k,i; k=sqrt(num); for(i=3;i<=k;i+=2)if(num%i==0)break; if(i<=k)return 0; return 1; } int main() { int prime[11010],n,c,sum,i,she,flag; for(i=1;i<=11000;i++)prime[i]=0; prime[2]=1;prime[1]=1; for(i=3;i<11000;i+=2)if(checkp(i))prime[i]=1; while(cin>>n>>c) { cout<<n<<" "<<c<<": "; if(n==1){cout<<1<<endl<<endl;continue;} sum=0; for(i=1;i<=n;i++)if(prime[i])sum++; if(sum%2==0) { if(2*c>sum)c=sum/2; she=sum/2-c; flag=0; for(i=1;;i++) { if(flag==she)break; if(prime[i])flag++; } i--; flag=0; for(i=i+1;;i++) { if(prime[i]) { cout<<i<<" "; flag++; if(flag==2*c-1)break; } } for(i=i+1;;i++)if(prime[i]){cout<<i<<endl<<endl;break;} } else { if(2*c-1>sum)c=(sum+1)/2; she=(sum+1)/2-c; if(she<0)she=0; flag=0; for(i=1;;i++) { if(flag==she)break; if(prime[i])flag++; } i--; flag=0; for(i=i+1;;i++) { if(prime[i]) { cout<<i<<" "; flag++; if(flag==2*c-2)break; } } for(i=i+1;;i++)if(prime[i]){cout<<i<<endl<<endl;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