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 |
骗人 1《=N《=1000 竟然有-1#include<iostream> #include<string> #include<cmath> using namespace std; int a[1200]; int cnt=0; int isPrime(int n){ if(n==0)return 0; if(n==1||n==2)return 1; for(int i=2;i<=sqrt(n*1.0);i++){ if(n%i==0)return 0; } return 1; } void cal(void){ memset(a,0,sizeof(a)); for(int i=1;i<=1000;i++){ if(isPrime(i)){ a[cnt]=i; cnt++; } } } int find(int n){ if(n==0)return -1;//删掉此行 RE for(int i=0;i<cnt;i++) if(a[i]==n)return i; for(int i=0;i<cnt;i++){ if(a[i]>n)return i-1; } } void solve(int n,int c){ int t=find(n)+1; printf("%d %d:",n,c); if(t%2==0){ if(2*c>t){ for(int i=0;i<cnt;i++){ if(a[i]<=n)cout<<" "<<a[i]; } } else{ int temp=(t-2*c)/2; int C=2*c; while(C--){ cout<<" "<<a[temp]; temp++; } } cout<<endl<<endl; } else if(t%2!=0){ if(2*c-1>t){ for(int i=0;i<cnt;i++){ if(a[i]<=n)cout<<" "<<a[i]; } } else{ int temp=(t-(2*c-1))/2; int C=2*c-1; while(C--){ cout<<" "<<a[temp]; temp++; } } cout<<endl<<endl; } } int main (){ int a,b; cal(); while(scanf("%d%d",&a,&b)!=EOF){ solve(a,b); } system("pause"); return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator