题意 给出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. Java 控制语句:循环、条件判断

    基础很重要,基础很重要,基础很重要.重要的事情说三遍,. 程序设计中的控制语句主要有三种:顺序.分支和循环.我们每天写的代码,除了业务相关,里面会包含大量的控制语句.但是控制语句的基本使用,是否有些坑 ...

  2. python3 urllib及requests基本使用

    在python中,urllib是请求url连接的标准库,在python2中,分别有urllib和urllib,在python3中,整合成了一个,称谓urllib 1.urllib.request re ...

  3. 五、xadmin自定义插件2

    以导入插件为例说明: 1.在xadmin-->plugins下面新建excel.py文件 2.新建ListExcelImportPlugin类,继承BaseAdminPlugin from xa ...

  4. configure: error: cannot guess build type; you must specify one解决方法

    原文地址:https://blog.csdn.net/hebbely/article/details/53993141 1.configure: error: cannot guess build t ...

  5. 【转】mysql热备

    mysql双机热备的实现 亲测可用

  6. Spring配置文件beans.xml头部配置解释

    Spring配置文件beans.xml头部配置解释 - EasonJim - 博客园https://www.cnblogs.com/EasonJim/p/6880329.html

  7. Web系统大规模并发——秒杀与抢购 秒杀系统优化与预防措施

    电商的秒杀和抢购,对我们来说,都不是一个陌生的东西.然而,从技术的角度来说,这对于Web系统是一个巨大的考验.当一个Web系统,在一秒钟内收到数以万计甚至更多请求时,系统的优化和稳定至关重要.这次我们 ...

  8. 对于vue和react“页面间”传递数据的理解误区

    前言 如果我们想要实现多个标签页之间的通信,可以使用localStorage.cookie等,但是能不能用vue或react呢? 结论 答案是NO,因为vue和react虽然可以在“多个”页面之间传递 ...

  9. Kafka-Flume-elasticsearch

    a1.sources = kafkaSource a1.channels = memoryChannel a1.sinks = elasticsearch a1.sources.kafkaSource ...

  10. null值经过强转会怎样?

    null还是null,类型不会改变的,也不会报错!