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 |
16ms#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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator