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 很显然这是一题有关于素数的题目. 注意数据的范围,爆搜超时无误. 这里要用到筛选法求素数. ...
随机推荐
- CentOS7_RAID5_LVM_SAMBA
1.在CentOS 7上构建RAID5.LVM和SAMBA服务器(1)——预备http://blog.csdn.net/kingfox/article/details/51099617 2.在Cent ...
- commons-logging日志系统
日志的重要性是随着系统的膨胀而显现的,在一个庞大的系统中查错没有各种日志信息 是寸步难行的.所以在系统加入日志是必须的. 最原始的日志方式,就是在程序的适当地方添加System.out.prin ...
- ora-01033:oracle initialization or shutdown in progress 解决方法
今天研究Oracle遇到了这个问题ora-01033:oracle initialization or shutdown in progress,经过分析研究终于解决了,写下来纪念一下.我的库是ora ...
- 使用poi读写Excel
对于一个程序员来说,文件操作是经常遇到的,尤其是对Excel文件的操作. 在这里介绍一下我在项目中用到的一个操作Excel的工具——POI.关于POI的一些概念,网络上很多,详细信息大家可以自行百度, ...
- Maven——聚合与继承
原文:http://www.cnblogs.com/xdp-gacl/p/4058008.html 一.聚合 如果我们想一次构建多个项目模块,那我们就需要对多个项目模块进行聚合 1.1.聚合配置代码 ...
- Sqlserver_时间用法
函数 描述 GETDATE() 返回当前的日期和时间 DATEPART() 返回日期/时间的单独部分 DATEADD() 在日期中添加或减去指定的时间间隔 DATEDIFF() 返回两个日期之间的时间 ...
- openfire控制台登录不了的解决
不知道为什么,openfire服务器后台,发生几次密码都登录不上去的问题,密码肯定没错,第一次就是默认的用户名:admin,密码:admin,然,第三天,说我密码错误,后来重装软件才弄好, 然后又发生 ...
- jQuery内置函数 ready
jQuery给我们提供了一些非常实用的函数 ready:加载函数 传统事件只能绑定一个函数 后面的函数会把前面的函数覆盖 js中用的是 window.onload = function(){}; j ...
- postgresql异常快速定位
今天下午在使用.NET链接postgresql的时候报了“3D000”的错误,经过测试得知原来是web.config中的数据库配置问题. 在这里有个小情况需要注意,postgresql是不允许创建相同 ...
- stackview
Stack View会被当成Container View.所以它是一个不会被渲染的UIView子类.它不像其他UIView子类一样,会被渲染到屏幕上.这也意味着设置其backgroundColor属性 ...