首页 > 其他 > 详细

POJ 3006 Dirichlet's Theorem on Arithmetic Progressions 素数 难度:0

时间:2015-07-23 00:24:18      阅读:205      评论:0      收藏:0      [点我收藏+]

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

#include <cstdio>
using namespace std;
bool pm[1000002];
bool usd[1000002];
bool judge(int x)
{
    if(usd[x])return pm[x];
    usd[x] = true;
    if(x == 2) return pm[x] = true;
    if(((x & 1) == 0) || (x < 2))return pm[x] = false;
    for(int i = 3;i * i <= x;i+= 2)
    {
        if(x % i == 0)return pm[x] = false;
    }
    return pm[x] = true;
}

int main(){
    int a,d,n;
    while(scanf("%d%d%d",&a,&d,&n) == 3 && a)
    {
        int cnt = 0;
        for(int tn = 0;tn < n;cnt++)
        {
            if(judge(cnt * d + a))tn++;
            if(tn == n)break;
        }
        printf("%d\n",cnt * d + a);
    }

    return 0;
}

 

POJ 3006 Dirichlet's Theorem on Arithmetic Progressions 素数 难度:0

原文:http://www.cnblogs.com/xuesu/p/4668916.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!