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 |
大家帮我看看,哪里错了啊,快崩溃了#include<iostream> using namespace std; int prime[1000]; bool is_prime(int n) { if(n==1||n==2)return 1; int i; if((n!=2&&n%2==0)||(n!=3&&n%3==0)||(n!=5&&n%5==0)||(n!=7&&n%7==0)||(n!=11&&n%11==0)) return 0; for(i=1;prime[i]*prime[i]<n;i++) if(n%prime[i]==0)return 0; return 1; } int main() { int n,c,k,i,s,time; while(cin>>n>>c) { k=0; for(i=1;i<=n;i++) if(is_prime(i))prime[k++]=i; if(k%2) if(k>=2*c-1){s=(k-2*c+1)/2;time=2*c-1;} else {s=0;time=k;} else if(k>=2*c){s=(k-2*c)/2;time=2*c;} else {s=0;time=k;} cout<<n<<" "<<c<<":"; while(time--) cout<<" "<<prime[s++]; cout<<endl<<endl; } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator