POJ 3006 Dirichlet's Theorem on Arithmetic Progressions 素数 难度:0
http://poj.org/problem?id=3006
#include <cstdio>
using namespace std;
bool pm[1000002];
bool usd[1000002];
bool judge(int x)
{
if(usd[x])return pm[x];
usd[x] = true;
if(x == 2) return pm[x] = true;
if(((x & 1) == 0) || (x < 2))return pm[x] = false;
for(int i = 3;i * i <= x;i+= 2)
{
if(x % i == 0)return pm[x] = false;
}
return pm[x] = true;
} int main(){
int a,d,n;
while(scanf("%d%d%d",&a,&d,&n) == 3 && a)
{
int cnt = 0;
for(int tn = 0;tn < n;cnt++)
{
if(judge(cnt * d + a))tn++;
if(tn == n)break;
}
printf("%d\n",cnt * d + a);
} return 0;
}
POJ 3006 Dirichlet's Theorem on Arithmetic Progressions 素数 难度:0的更多相关文章
- 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 ...
- 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 分类: POJ 2015-06-12 21:07 7人阅读 评论(0) 收藏
Dirichlet's Theorem on Arithmetic Progressions Time Limit: 1000MS Memory Limit: 65536K Total Submi ...
- Dirichlet's Theorem on Arithmetic Progressions POJ - 3006 线性欧拉筛
题意 给出a d n 给出数列 a,a+d,a+2d,a+3d......a+kd 问第n个数是几 保证答案不溢出 直接线性筛模拟即可 #include<cstdio> #inclu ...
- 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 ...
- (素数求解)I - Dirichlet's Theorem on Arithmetic Progressions(1.5.5)
Time Limit:1000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u Submit cid=1006#sta ...
- Dirichlet's Theorem on Arithmetic Progression
poj3006 Dirichlet's Theorem on Arithmetic Progressions 很显然这是一题有关于素数的题目. 注意数据的范围,爆搜超时无误. 这里要用到筛选法求素数. ...
随机推荐
- SQL 总结
1. select 使用正则表达式 正则表达式的模式串, 与linux基本相同, oracle提供以下4个函数来支持正则表达式: REGEXP_LIKE: 比较一个字符串是否与正则表达式匹配(看来是返 ...
- sqlplus入门基础语句
关于Oracle 首先Oracle一个数据库由若干个表空间组成,每个表空间由若干个数据文件(或设备)组成,每个数据文件由若干个盘区组成,每个盘区由若干个block组成.这是Oracle的物理结构. 逻 ...
- JavaWeb学习总结(八)—Cookie
1.什么叫Cookie Cookie翻译成中文是小甜点,小饼干的意思.在HTTP中它表示服务器送给客户端浏览器的小甜点.其实Cookie就是一个键和一个值构成的,随着服务器端的响应发送给客户端浏览器. ...
- Javascript模块化编程(一):模块的写法 (转载 学习中。。。。)
转载地址:http://www.ruanyifeng.com/blog/2012/10/javascript_module.html 阮一峰 大神:http://www.ruanyifeng.com/ ...
- python类、对象、方法、属性之类与对象笔记
python中一切皆为对象,所谓对象:我自己就是一个对象,我玩的电脑就是对象,坐着的椅子就是对象,家里养的小狗也是一个对象...... 我们通过描述属性(特征)和行为来描述一个对象的.比如家里的小狗, ...
- Windows 内存架构
理解 Virtual Memory, Physical Memory, Committed Memory, Page File, Working Set, Modified Pages, Standb ...
- hiho_1059_string matching content length
题目大意 两个字符串strA和strB(长度最大为2100),他们中按照顺序有一些公共的子串,且公共子串的长度大于等于3,否则不认为是合法的,比如 abcdef 和 abcxcdef, 按照顺序有合法 ...
- mismatch位置(MD tag)- sam/bam格式解读进阶
这算是第二讲了,前面一讲是:Edit Distance编辑距离(NM tag)- sam/bam格式解读进阶 MD是mismatch位置的字符串的表示形式,貌似在call SNP和indel的时候会用 ...
- python 暴力破解密码脚本
python 暴力破解密码脚本 以下,仅为个人测试代码,环境也是测试环境,暴力破解原理都是一样的, 假设要暴力破解登陆网站www.a.com 用户 testUser的密码, 首先,该网站登陆的验证要支 ...
- java 导入包
导入包 问题:类名冲突时,要如何解决. 解决:sun提供导入包语句让我们解决该问题. 导入包语句的作用:简化书写. 导入包语句的格式:import 包名.类名;(导入xxx包的XX类) 导入包语句的细 ...