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 wocha at 2012-07-14 13:51:54 on Problem 3006
#include<stdio.h>
#include<math.h>
int prime[1000000+9];

void prim()
{
    prime[0]=1;
    prime[1]=1;
    int i,j,n,m;
    for(i=2;i<=1000000;i++)
     {
         if(prime[i]==0)
         {
            for(j=2;;j++)
            {
                if(j*i<=1000000)
                prime[j*i]=1;
                else
                break;
            }
         }
     }
}
int main()
{
    prim();
    int i,j,n,m,l;
    int a,d;
    while(~scanf("%d%d%d",&a,&d,&n))
    {
        if(a==0&&d==0&&n==0)
        break;
      int cnt=0;
      for(i=a;;i+=d)
      {
            if(prime[i]==0)
            {
                cnt++;
                if(cnt==n)
               { printf("%d\n",i);break;}
            }

      }
    }
    
}

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