POJ3306 素数筛法

简介:

这题很明显得用素数筛法打出一个素数表 模拟一下求出第n个素数就可以了 

水题啊。。。。

#include <iostream>
#include<cstdio>
#include<cstring>
using namespace std;
#define max 1000005
bool isprime[max];
void getprime()
{
    long long i,j;
    memset(isprime,1,sizeof(isprime));
    isprime[1]=0;
    isprime[0]=0;
    for(i=2; i<max; i++)
        if(isprime[i])
            for(j=i*i; j<max; j+=i)
                isprime[j]=0;
}
int main()
{
    getprime();
    int a,d,n;
    while(~scanf("%d%d%d",&a,&d,&n)&&(a+d+n))
    {
        int i,sum=0;
        for(i=a; sum<n; i+=d)
            if(isprime[i])
            {
                sum++;
                if(sum==n)
                    break;
            }
        printf("%d\n",i);
    }
    return 0;
}


目录
相关文章
|
人工智能
POJ 3104 Drying
POJ 3104 Drying
|
C语言
poj 2503 查字典
Description You have just moved from Waterloo to a big city. The people here speak an incomprehensible dialect of a foreign language.
865 0
POJ 2487 Stamps
Description Background Everybody hates Raymond. He’s the largest stamp collector on planet earth and because of that he always makes fun of all the others at the stamp collector parties.
1062 0
poj题目分类
http://www.cnblogs.com/kuangbin/archive/2011/07/29/2120667.html
770 0
|
机器学习/深度学习 Windows
|
消息中间件 人工智能 JavaScript