题意 给出a d n    给出数列 a,a+d,a+2d,a+3d......a+kd 问第n个数是几 保证答案不溢出

  直接线性筛模拟即可

 #include<cstdio>
#include<cstring>
using namespace std;
bool Is_Primes[];
int Primes[];
int A[];
int cnt;
void Prime(int n){
cnt=;
memset(Is_Primes,,sizeof(Is_Primes));
for(int i=;i<=n;i++){
if(!Is_Primes[i])
Primes[cnt++]=i;
for(int j=;j<cnt&&i*Primes[j]<n;j++){
Is_Primes[i*Primes[j]]=;
if(i%Primes[j]==)break;
}
} memset(Is_Primes,,sizeof(Is_Primes));
for(int i=;i<cnt;i++){
Is_Primes[Primes[i]]=;
} }
int main(){
int a,b,n;
Prime();
while(scanf("%d%d%d",&a,&b,&n)==&&a+b+n){ int ans=;
for(int i=;i<;i++){
A[i]=i*b +a;
// printf("%d %d\n",A[i],i);
if(Is_Primes[A[i]])ans++;
if(ans==n){
ans=A[i];
break;
}
}
printf("%d\n",ans); }
return ;
}

Dirichlet's Theorem on Arithmetic Progressions POJ - 3006 线性欧拉筛的更多相关文章

  1. Goldbach's Conjecture POJ - 2262 线性欧拉筛水题 哥德巴赫猜想

    题意 哥德巴赫猜想:任一大于2的数都可以分为两个质数之和 给一个n 分成两个质数之和 线行筛打表即可 可以拿一个数组当桶标记一下a[i]  i这个数是不是素数  在线性筛后面加个装桶循环即可 #inc ...

  2. Sum of Consecutive Prime Numbers POJ - 2739 线性欧拉筛(线性欧拉筛证明)

    题意:给一个数 可以写出多少种  连续素数的合 思路:直接线性筛 筛素数 暴力找就行   (素数到n/2就可以停下了,优化一个常数) 其中:线性筛的证明参考:https://blog.csdn.net ...

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

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

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

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

  5. 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 ...

  6. 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 ...

  7. 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 ...

  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. 线程GIL锁 线程队列 回调函数

    ----------------------------------无法改变风向,可以调整风帆;无法左右天气,可以调整心情.如果事情无法改变,那就去改变观念. # # ---------------- ...

  2. nginx负载均衡精简配置实例

    [root@localhost ~]# vim nginx.conf user nginx; worker_processes ; error_log /var/log/nginx/error.log ...

  3. VirtualBox安装复制Centos6.6配置网络

    由于要搭建mongodb的集群,先用虚拟机做下相关实验,以前都用VM Vare,但是现在这个电脑的配置不是太好,VM Vare比较耗资源,所以选择VirtualBox. 1.下载VirtualBox和 ...

  4. Of Study

    Bacon Reading maketh a full man; conference a ready man; and writing an exact man. And therefore, if ...

  5. Hive基础

    一.常用语句 二.嵌套语句 以上两句的查询结果相同. 三.关键字查询

  6. LINUX操作系统(centos6.9)安装与配置

    LINUX操作系统(centos6.9)安装与配置_百度经验 https://jingyan.baidu.com/article/acf728fd6bdba1f8e510a3f7.html cento ...

  7. winform使用相关

    1.回车键触发按钮点击事件——回车登录 设置窗体的AccessButton属性 2.密码框样式设置 设置PasswordChar为想要的密码显示的样式,如*  3.设置窗口居中 设置StartPosi ...

  8. sql之cursor的简介和字符串拆分(split)与游标的使用

     字符串拆分(split)与游标的使用 CREATE TABLE Plates ( ,), ) NOT NULL, [BusinessId] INT NOT NULL, ) ),),), SELECT ...

  9. C#设计模式之1:策略模式

    首先需要说明的是该系列的所有内容都是基于headfirst设计模式来描述的.因为我之前也看过不少关于设计模式的书,还是发现这本最好,因为这本书里面给出的例子是最贴切实际的.不说了,开始这个系列吧! 策 ...

  10. Oracle RMAN备份与还原注意事项

    1 备份文件管理 如果要删除之前的备份,不要手动去目录下删除,应该在rman命令模式下使用删除命令,否则虽然在磁盘上把物理备份文件删除了,但是使用备份查看命令会一直看到已经删除的备份文件 list b ...