Dirichlet's Theorem on Arithmetic Progressions

http://poj.org/problem?id=3006

 #include<stdio.h>
#include<math.h>
int is_prime(int n)
{
int i,m;
if (n==)
return ;
m = sqrt(n);
for (i = ; i <= m; i ++)
{
if (n%i==)
return ;
}
return ;
}
int main()
{
int a,d,n,i;
while(~scanf("%d%d%d",&a,&d,&n))
{
int cnt = ;
if (a==&&d==&&n==)
break;
for (i = a;; i =i+d)
{
if(is_prime(i))
cnt++;
if(cnt==n)
break;
}
printf("%d\n",i);
}
return ;
}
上一篇:LeetCode(五)


下一篇:【POJ3006】Dirichlet's Theorem on Arithmetic Progressions(素数筛法)