poj3006
来源:互联网 发布:豆瓣与知乎哪个实用 编辑:程序博客网 时间:2024/06/10 19:09
//其实就是不停的判断素数,网上有些人是先打了个素数表,要注意对1的判断!!!#include <iostream>#include <cmath>using namespace std;int a,d,n;int count;bool is_prime(long x){ if(x==1) //千万注意 { return false; } for(int i=2;i*i<=x;i++) { if((x!=0)&&(x%i==0)) { return false; } } return true;}int main(){ while(cin>>a>>d>>n,(a+d+n)) { count=0; long x=a; while(count!=n) { if(is_prime(x)==true) { count++; } x=x+d; } if(a=1&&d==1&&n==1) cout<<2<<endl; else { cout<<x-d<<endl; } } return 0;}