POJ 3006 Dirichlet's Theorem on Arithmetic Progressions
/**************************************
Problem: POJ 3006 Dirichlet's Theorem on Arithmetic Progressions
Time: 79MS
Memory: 1180K
Accepted Time: 2009-05-17 10:41:54
Tips:
**************************************/
#include <stdio.h>
#include <string.h>
#define MAX 1000000
int main()
{
bool num[MAX+1];
memset(num,true,sizeof(num));
num[1]=false;
int i,j;
for(i=2;i<=MAX/2;i++)
if(num[i])for(j=2;i*j<=MAX;j++)num[i*j]=false;
int a,d,n;
while(1)
{
scanf("%d%d%d",&a,&d,&n);
if(a==0&&d==0&&n==0)break;
int count=0;
while(count!=n)
{
if(num[a])count++;
a+=d;
}
printf("%d\n",a-d);
}
return 0;
}
Problem: POJ 3006 Dirichlet's Theorem on Arithmetic Progressions
Time: 79MS
Memory: 1180K
Accepted Time: 2009-05-17 10:41:54
Tips:
**************************************/
#include <stdio.h>
#include <string.h>
#define MAX 1000000
int main()
{
bool num[MAX+1];
memset(num,true,sizeof(num));
num[1]=false;
int i,j;
for(i=2;i<=MAX/2;i++)
if(num[i])for(j=2;i*j<=MAX;j++)num[i*j]=false;
int a,d,n;
while(1)
{
scanf("%d%d%d",&a,&d,&n);
if(a==0&&d==0&&n==0)break;
int count=0;
while(count!=n)
{
if(num[a])count++;
a+=d;
}
printf("%d\n",a-d);
}
return 0;
}