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<iostream> #include<math.h> #define NUM 1111 using namespace std; int prime[NUM]={0,1,2,3}; int time[NUM]; int f() { int i,j; for(i=0;i<=3;i++) time[i]=i; time[4]=time[3]; int n=4,flag=0; for(i=5;i<=NUM;i++) { flag=0; for(j=2;j<=(int)sqrt(i*1.0);j++) if(i%j==0) { flag=1; break; } if(flag==0) prime[n++]=i; time[i]=n-1; } return 1; } int main() { int n,k,i; f(); while(cin>>n>>k) { cout<<n<<' '<<k<<": "; if(time[n]%2==0) { if(time[n]<=2*k) { for(i=1;i<=time[n];i++) cout<<prime[i]<<' '; cout<<endl; } else { for(i=time[n]/2-k+1;i<=time[n]/2+k;i++) cout<<prime[i]<<' '; cout<<endl; } } else { if(time[n]<=2*k-1) { for(i=1;i<=time[n];i++) cout<<prime[i]<<' '; cout<<endl; } else { for(i=time[n]/2+1-(2*k-1)/2;i<=time[n]/2+1+(2*k-1)/2;i++) cout<<prime[i]<<' '; cout<<endl; } } cout<<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