题目大意:给出一个等差数列,问这个等差数列的第n个素数是什么。

思路:这题主要考怎样筛素数,线性筛。详见代码。

CODE:

#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#define MAX 1000010
using namespace std; int prime[MAX],primes;
bool notp[MAX]; int a,d,n; void Pretreatment()
{
notp[1] = true;
for(int i = 2; i < MAX; ++i) {
if(!notp[i])
prime[++primes] = i;
for(int j = 1; j <= primes && i * prime[j] < MAX; ++j) {
notp[i * prime[j]] = true;
if(i * prime[j] == 0)
break;
}
}
} int main()
{
Pretreatment();
while(scanf("%d%d%d",&a,&d,&n),a + d + n) {
for(int now = a;; now += d) {
if(!notp[now]) --n;
if(!n) {
printf("%d\n",now);
break;
}
}
}
return 0;
}

POJ 3006 Dirichlet&#39;s Theorem on Arithmetic Progressions 快筛质数的更多相关文章

  1. (素数求解)I - Dirichlet&#39;s Theorem on Arithmetic Progressions(1.5.5)

    Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u Submit cid=1006#sta ...

  2. poj 3006 Dirichlet's Theorem on Arithmetic Progressions【素数问题】

    题目地址:http://poj.org/problem?id=3006 刷了好多水题,来找回状态...... Dirichlet's Theorem on Arithmetic Progression ...

  3. POJ 3006 Dirichlet's Theorem on Arithmetic Progressions (素数)

    Dirichlet's Theorem on Arithmetic Progressions Time Limit: 1000MS   Memory Limit: 65536K Total Submi ...

  4. Dirichlet's Theorem on Arithmetic Progressions 分类: POJ 2015-06-12 21:07 7人阅读 评论(0) 收藏

    Dirichlet's Theorem on Arithmetic Progressions Time Limit: 1000MS   Memory Limit: 65536K Total Submi ...

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

    http://poj.org/problem?id=3006 #include <cstdio> using namespace std; bool pm[1000002]; bool u ...

  6. poj 3006 Dirichlet's Theorem on Arithmetic Progressions

    题目大意:a和d是两个互质的数,则序列a,a+d,a+2d,a+3d,a+4d ...... a+nd 中有无穷多个素数,给出a和d,找出序列中的第n个素数 #include <cstdio&g ...

  7. Dirichlet's Theorem on Arithmetic Progressions POJ - 3006 线性欧拉筛

    题意 给出a d n    给出数列 a,a+d,a+2d,a+3d......a+kd 问第n个数是几 保证答案不溢出 直接线性筛模拟即可 #include<cstdio> #inclu ...

  8. Dirichlet's Theorem on Arithmetic Progressions

    http://poj.org/problem?id=3006 #include<stdio.h> #include<math.h> int is_prime(int n) { ...

  9. 【POJ3006】Dirichlet's Theorem on Arithmetic Progressions(素数筛法)

    简单的暴力筛法就可. #include <iostream> #include <cstring> #include <cmath> #include <cc ...

随机推荐

  1. 网站压力测试工具-Webbench源码笔记

    Ubuntu 下安装使用 1.安装依赖包CTAGS sudo apt-get install ctage 2.下载及安装 Webbench http://home.tiscali.cz/~cz2105 ...

  2. EF Code First学习笔记

    EF Code First学习笔记 初识Code First EF Code First 学习笔记:约定配置 Entity Framework 复杂类型 Entity Framework 数据生成选项 ...

  3. 关于Activity的少许细节

    1.  对活动应用样式和主题 2.  隐藏活动标题 3. 显示对话框窗口 4. 显示进度对话框 1.  应用样式和主题 改成 android:theme="@android:style/Th ...

  4. 【C#】用C#通过读取数据库方式读取CSV文件

    using System; using System.Collections.Generic; using System.Linq; using System.Windows.Forms; names ...

  5. JavaScript操作DOM的那些坑

    js在操作DOM中存在着许多跨浏览器方面的坑,本文花了我将近一周的时间整理,我将根据实例整理那些大大小小的“坑”. DOM的工作模式是:先加载文档的静态内容.再以动态方式对它们进行刷新,动态刷新不影响 ...

  6. Scrum概述

    • 敏捷方法是一类软件开发流程的泛称: • 敏捷方法是相对于传统的瀑布式软件过程提出的: • 敏捷方法可以用敏捷宣言(4条).敏捷原则(12条)来概括: • 敏捷原则通过一系列的敏捷实践来体现出来: ...

  7. WebService调用一对多关联关系时出现 死循环:A cycle is detected in...

    通过WebService调用一对多关联关系时引起的问题:A cycle is detected in the object graph 具体异常信息: org.apache.cxf.intercept ...

  8. 深入浅出谈存储:如何区别NAS、SAN与DAS

    深入浅出谈存储:如何区别NAS.SAN与DAS 2012年02月17日16:51 来源:新浪博客 作者:林沛满 编辑:曾智强 查看全文 赞(0)评论(1) 分享 标签: DAS , SAN , 存储系 ...

  9. WIN7 WIN8 笔记本无线网卡MAC地址修改

    找了好久,尝试了好多种方法,最后终于在下面的网址里找到了解决方案 http://jingyan.baidu.com/article/ceb9fb10e32bce8cac2ba04a.html 使用MA ...

  10. UVALive 7077 - Little Zu Chongzhi's Triangles(暴力)

    https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_probl ...