poj3006

Dirichlet's Theorem on Arithmetic Progressions

#include "iostream" #include "math.h" using namespace std; bool isPrime(int x); int main(int argc, _TCHAR* argv[]) { int a,d,n; cin>>a; cin>>d; cin>>n; while(a!=0||d!=0||n!=0) { int i=0; while(i!=n) { if(isPrime(a)) i++; a=a+d; } cout<<a-d<<endl; cin>>a; cin>>d; cin>>n; } system("pause"); return 0; } bool isPrime(int x) { if(x==1)return false; if(x==2)return true; for(int i=2;i<=sqrt((float)x)+1;i++) { if(x%i==0)return false; } return true; }

你可能感兴趣的:(poj3006)