Dirichlet's Theorem on Arithmetic Progressions POJ - 3006 线性欧拉筛
题意 给出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 线性欧拉筛的更多相关文章
- Goldbach's Conjecture POJ - 2262 线性欧拉筛水题 哥德巴赫猜想
题意 哥德巴赫猜想:任一大于2的数都可以分为两个质数之和 给一个n 分成两个质数之和 线行筛打表即可 可以拿一个数组当桶标记一下a[i] i这个数是不是素数 在线性筛后面加个装桶循环即可 #inc ...
- Sum of Consecutive Prime Numbers POJ - 2739 线性欧拉筛(线性欧拉筛证明)
题意:给一个数 可以写出多少种 连续素数的合 思路:直接线性筛 筛素数 暴力找就行 (素数到n/2就可以停下了,优化一个常数) 其中:线性筛的证明参考:https://blog.csdn.net ...
- poj 3006 Dirichlet's Theorem on Arithmetic Progressions【素数问题】
题目地址:http://poj.org/problem?id=3006 刷了好多水题,来找回状态...... Dirichlet's Theorem on Arithmetic Progression ...
- POJ 3006 Dirichlet's Theorem on Arithmetic Progressions (素数)
Dirichlet's Theorem on Arithmetic Progressions Time Limit: 1000MS Memory Limit: 65536K Total Submi ...
- 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 ...
- 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 ...
- 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 ...
- Dirichlet's Theorem on Arithmetic Progressions
http://poj.org/problem?id=3006 #include<stdio.h> #include<math.h> int is_prime(int n) { ...
- 【POJ3006】Dirichlet's Theorem on Arithmetic Progressions(素数筛法)
简单的暴力筛法就可. #include <iostream> #include <cstring> #include <cmath> #include <cc ...
随机推荐
- 图片自适应完美兼容IE8
<!DOCTYPE html><html lang="en"><head> <meta charset="gb2312" ...
- socketserver + ftp
--------------------------------------------生活不止眼前的苟且,还有诗和远方的田野. day 29 socketserver + ftp # # ----- ...
- OSGI基础环境搭建
1.安装jdk,步骤自行搜索 2.下载eclipse,用luna版本,下载地址: https://pan.baidu.com/s/1gdfmW5znU4fltsLCAo8tkg 提取码: nrg7 3 ...
- Python_每日习题_0004_一年中的第几天
# 题目 输入某年某月某日,判断这一天是这一年的第几天? # 程序分析 特殊情况,闰年时需考虑二月多加一天: def isLeapYear(y): return (y%400==0 or (y%4== ...
- 广州商学院16级软工一班&二班-第二次作业成绩
作业地址 https://edu.cnblogs.com/campus/gzcc/GZCC-16SE2/homework/2097 https://edu.cnblogs.com/campus/gzc ...
- java总结:double取两位小数的多种方法
1.方法一 四舍五入: import java.math.BigDecimal; double f = 111231.5585; BigDecimal b = new BigDecimal(f); d ...
- Linux下设置MySql自动启动
https://www.cnblogs.com/sunny3096/p/7954146.html
- MyEclipse10 复制之前的项目部署到tomcat时项目名称对不上,还是复制前的项目名称,哪里修改设置
工程 -- 右键属性 -- Myeclispse -- web修改一下发布名字就可以了.
- Azure系列2.1.12 —— CloudBlobDirectory
(小弟自学Azure,文中有不正确之处,请路过各位大神指正.) 网上azure的资料较少,尤其是API,全是英文的,中文资料更是少之又少.这次由于公司项目需要使用Azure,所以对Azure的一些学习 ...
- Dom4j解析
dom4j-1.6.1.jar, 这个包提供了xml解析相关的方法. 这里做一个记录,微信公众号里需要对HttpServletRequest做解析,实际上也可以用dom4j提供的方法进行解析转换. 这 ...