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

16ms

Posted by jhldreams at 2014-05-26 12:25:53 on Problem 3006
#include <iostream>
#include<cmath>
#include<cstdio>
#include<cstring>
#define MAXN 1000000
using namespace std;

int main()
{
    bool vis[MAXN];
	memset(vis,false,sizeof(vis));
	vis[1]=true;
	int i,j;
    for(i=2;i<(int)sqrt((double)MAXN);i++)
    {
        if(!vis[i])
        {
            for(j=i*i;j<MAXN;j+=i)
                vis[j]=true;
        }
    }
    int a,d,n;
    while(scanf("%d%d%d",&a,&d,&n)!=EOF&&a!=0&&d!=0&&n!=0)
    {
        int sum=0,flag=0;
        for(i=1,j=i;i<=n;i++)
        {
            sum = a + (j-1)*d;
			if(vis[sum]==false)
				j++;
            while(vis[sum]==true)
            {
                j++;
                sum = a + (j-1)*d;
				flag=1;
            }
			if(flag==1)
			{
				j++;
				flag=0;
			}

        }
        cout<<sum<<endl;
    }
    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