标签:
题目大意:a和d是两个互质的数,则序列a,a+d,a+2d,a+3d,a+4d ...... a+nd 中有无穷多个素数,给出a和d,找出序列中的第n个素数
1 #include <cstdio> 2 3 int isPrime(int n) 4 { 5 if(n == 1 || (n != 2 && n % 2 == 0)) 6 return 0; 7 for(int i = 2; i*i <= n; ++i) 8 if(n%i == 0) 9 return 0; 10 return 1; 11 } 12 13 int main() 14 { 15 int a,d,n,cun,temp; 16 while(scanf("%d %d %d",&a,&d,&n) && a && d && n) 17 { 18 cun = 0; 19 for(int i = 0; cun != n; ++i) 20 { 21 temp = a + i*d; 22 if(isPrime(temp)) 23 ++cun; 24 } 25 printf("%d\n",temp); 26 } 27 return 0; 28 }
poj 3006 Dirichlet's Theorem on Arithmetic Progressions
标签:
原文地址:http://www.cnblogs.com/guoyongheng/p/5722640.html