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

我受不了了,天啊!是哪个地方错了啊???这样还错啊!帮帮我啊!

Posted by houxuanfelix at 2006-05-04 18:08:57 on Problem 1595
#include <stdio.h>
int main()
{
    int  i,j,k,c,n,l,flag,num[500];
    while (scanf ("%d%d",&n,&c)==2)
    {
          if (n==1)   printf ("%d %d: 1",n,c);
          else
          {
          for (i=0;i<500;i++)   num[i]=0;
          k=2;
          num[0]=1;num[1]=2;
          for (i=3;i<=n;i++)
          {
              flag=0;
              for (j=2;j<i/2+2;j++)
                   if (i%j==0)  
                       flag=1;
              if (!flag)
              {
                   num[k]=i;
                   k++;
              }
          }
          printf ("%d %d:",n,c);
          if (n%2==0)
          {
              i=k/2;
              j=i-c;
              if (j<0)  j=0;
              for (;j<i;j++)   printf (" %d",num[j]);
              j=i+c;
              if (j>k)    j=k;
              for (;i<j;i++)   printf (" %d",num[i]);
          }
          else
          {
              i=k/2;
              j=i-c+1;
              if (j<0)  j=0;
              for(;j<i;j++)     printf (" %d",num[j]);
              j=i+c;
              if (j>k)  j=k; 
              for (;i<j;i++)    printf (" %d",num[i]);
          }
       }
       printf ("\n\n");
    }
     return 0;
}

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