Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

WHY RA?

Posted by luoyongbiao at 2006-04-18 12:08:21 on Problem 1595
#include "Stdio.h"
 main()
{
   int i,j,number,flag,shift;
   int prime[200];
   int N,C,all,start,s;
   prime[0]=1;
   prime[1]=2;
   number=2;
   for(i=3;i<1001;i++)
   {
       flag=1;
       for(j=1;j<=number;j++)
       {
            if(i%prime[j]==0)
            {
               flag=0;
               break;
            }
       }
       if(flag) {prime[number]=i; number++;}
   }  
   while(scanf("%d%d",&N,&C)==2)
   {
       for(i=0;i<number;i++)
       {
           if(N<prime[i]) break;
       }
       all=i;
       if(all%2) s=2*C-1;
       else     s=2*C;
       start=(i-s)/2;
       if(start<0) start=0;      
       printf("%d %d:",N,C);
	   shift=0;
       for(i=start;i<start+s;i++)
       {
           if((i>=number)||(prime[i]>N)) break; 
           printf(" %d",prime[i]);
		   shift++;
		   if(shift==17) {shift=0;printf("\n\n");}
       }
       printf("\n\n");
   } 
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator