poj3006Dirichlet's Theorem on Arithmetic Progressions(筛素数法)

Dirichlet‘s Theorem on Arithmetic Progressions Description If a and d are relatively prime positive integers, the arithmetic sequence beginning with a and increasing by d, i.e., a, a + d, a + 2d, a + 3d, a + 4d, ..., contains infinitely many prime numbers. This fact is known as Dirichlet's Theorem on. 阅读详情

原题链接

Dirichlet's Theorem on Arithmetic Progressions
Time Limit: 1000MS Memory Limit: 65536K
Total Submissions: 18252 Accepted: 9185

Description

If a and d are relatively prime positive integers, the arithmetic sequence beginning with a and increasing by d, i.e., a, a + d, a + 2d, a + 3d, a + 4d, ..., contains infinitely many prime numbers. This fact is known as Dirichlet's Theorem on Arithmetic Progressions, which had been conjectured by Johann Carl Friedrich Gauss (1777 - 1855) and was proved by Johann Peter Gustav Lejeune Dirichlet (1805 - 1859) in 1837.

For example, the arithmetic sequence beginning with 2 and increasing by 3, i.e.,

2, 5, 8, 11, 14, 17, 20, 23, 26, 29, 32, 35, 38, 41, 44, 47, 50, 53, 56, 59, 62, 65, 68, 71, 74, 77, 80, 83, 86, 89, 92, 95, 98, ... ,

contains infinitely many prime numbers

2, 5, 11, 17, 23, 29, 41, 47, 53, 59, 71, 83, 89, ... .

Your mission, should you decide to accept it, is to write a program to find the nth prime number in this arithmetic sequence for given positive integers a, d, and n.

Input

The input is a sequence of datasets. A dataset is a line containing three positive integers a, d, and n separated by a space. a and d are relatively prime. You may assume a <= 9307, d <= 346, and n <= 210.

The end of the input is indicated by a line containing three zeros separated by a space. It is not a dataset.

Output

The output should be composed of as many lines as the number of the input datasets. Each line should contain a single integer and should never contain extra characters.

The output integer corresponding to a dataset a, d, n should be the nth prime number among those contained in the arithmetic sequence beginning with a and increasing by d.

FYI, it is known that the result is always less than 106 (one million) under this input condition.

Sample Input

367 186 151
179 10 203
271 37 39
103 230 1
27 104 185
253 50 85
1 1 1
9075 337 210
307 24 79
331 221 177
259 170 40
269 58 102
0 0 0

Sample Output

92809
6709
12037
103
93523
14503
2
899429
5107
412717
22699
25673
题目大意:给出一个a,d,n。让你求出序列a,a+d,a+2d,a+3d.....中第N个素数。

解题思路:无耻的打了个表。。打表时要把isprime[1]改为false,在这里套模板时wa了一次。。然后直接判断就好了。

#include
  
   
#include
   
    
#include
    
     
using namespace std;
#define MAX 1000000
bool isprime[MAX+1];
void prime(){//打印一个素数表,这个算法很有用
	memset(isprime,true,sizeof(isprime));
	int i;
	isprime[1]=false;
	for(int i=2;i*i<=MAX;i++){
		if(isprime[i]){
			for(int j=i+i;j<=MAX;j=j+i){
				isprime[j]=false;
			}
		}
	}
}
int main(){
	prime();
	int n,a,d;
	while(scanf("%d %d %d",&a,&d,&n)&&n!=0&&a!=0&&d!=0){
		int flag=0;
		while(n>0){
			if(isprime[a]==true){
				n--;
			}
			a=a+d;
		}
		printf("%d\n",a-d);
	}
}
    
   
  


POJ3006-Dirichlet's Theorem on Arithmetic Progressions 北大POJ3006-Dirichlet's Theorem on Arithmetic Progressions 解题报告+AC代码 立即下载

相关推荐

欧姆龙PLC与fanuc发那科机器人进行Ethrenet ip通信测试

近期在做发那科FANUC的通讯,会吧CC-LINK、Profibus-DP、Profinet I/O、DeviceNet、EtherNet/IP这些常用通讯做成文档发上来,大家喜欢的话可以关注 注:做对应的通讯,在机器人控制柜都需要安装对应的板卡以及软件功能 截图中的程序设置和机器人EDS插件在下面链接 https://download.youkuaiyun.com/download/gojava/13770799 PLC为主站 机器人为从站 一、硬件部分 欧姆龙PLC ...

七兔自习室 1万+

Dirichlet's Theorem on Arithmetic Progressions 素数筛选法

题目描述If a and d are relatively prime positive integers, the arithmetic sequence beginning with a and increasing by d, i.e., a, a + d, a + 2d, a + 3d, a + 4d, ..., contains infinitely many prime numbers...

qq_41486817的博客 258

XY2-100协议解析

1.XY2-100包括四路信号 : SENDCK(时钟信号)、SYNC(同步信号)、CHANNELX(X通道)、CHANNELY(Y通道)

qq_38360574的博客 9532

POJ3006-Dirichlet's Theorem on Arithmetic Progressions解题报告

Dirichlet's Theorem on Arithmetic Progressions Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 11749   Accepted: 5923 Description If a and d are relatively p

princeyuan的专栏 989

解决Keil uVision许可证管理中Unknown Product错误

嵌入式开发中,IDE工具的许可证管理是确保开发环境正常运行的关键环节。Keil uVision作为ARM架构的主流开发工具,其许可证系统采用加密验证机制,通过产品版本识别实现授权控制。当出现Unknown Product错误时,通常源于版本兼容性问题或区域发行版差异,这直接影响开发工具链的可用性。特别是在维护历史项目或使用中国特供版时,开发者常会遇到此类问题。通过分析许可证类型、调整安装配置或建立虚拟化开发环境等工程实践方案,可以有效解决这类授权验证故障,保障嵌入式项目的持续集成与交付效率。

weixin_33743248的博客 363

R语言灰色关联分析法

输入数据并用DT包的datatable函数展示数据 ABDDEF分别对应第1到第6个供应商产品质量、技术水平、供应能力、经济效益、交货情况、市场影响度指标属于效益型指 产品价格、地理位置、售后服务指标属于成本型指标。现分别对上述指标进行规范化: 对于效益型指标(正项指标)标准化公式为: x∗=x−min(x)max(x)−min(x) x^{\ast}=\frac{x-min\left( x \right)}{max\left( x \right) -min\left( x \right)} x∗=max

qq_54423921的博客 7996

POJ 刷题系列:3006. Dirichlet's Theorem on Arithmetic Progressions

POJ 刷题系列:3006. Dirichlet’s Theorem on Arithmetic Progressions传送门:3006. Dirichlet’s Theorem on Arithmetic Progressions题意: 给出一个递增序列,求该递增序列中第n个素数。 思路: 这些水题怎么都有关素数的。。。实际上给定初项a和公差d,以及可能的素数,能判断该素数是否在这个递增数

Demon-初来驾到 522

OPNET卫星节点仿真避坑指南:为什么你的STK轨道文件导入后位置不对?

本文深入解析OPNET卫星节点仿真中STK轨道文件导入后位置异常的常见问题,揭示坐标系差异(ECI与ECF)、时间基准不匹配等关键因素。通过修改.SA文件头标识、统一时间基准等解决方案,帮助工程师避免仿真失真,提升卫星通信系统仿真的准确性。特别适用于STK与OPNET协同工作的卫星网络仿真场景。

weixin_30335575的博客 600

POJ 3006:Dirichlet's Theorem on Arithmetic Progressions题解报告(C++)

原题网址:http://poj.org/problem?id=3006题目描述:DescriptionIf a and d are relatively prime positive integers, the arithmetic sequence beginning with a and increasing by d, i.e., a, a + d, a + 2d, a + 3d, a + ...

一步一脚印 419

ARM学习 | 紧耦合存储器 (TCM)

TCM 是一种专用的片上存储器,直接与处理器核心耦合。确定性访问:由于不涉及缓存替换或一致性管理,访问延迟固定。高带宽:TCM 通常通过专用总线连接处理器核心,可以提供更高的数据吞吐率。用户管理:TCM 的分配和管理完全由开发者控制,不依赖硬件缓存策略。ARM 处理器中的 TCM 通常分为ITCM(指令紧耦合存储器)和DTCM(数据紧耦合存储器),分别用于存储指令和数据。TCM 是 ARM 处理器中不可忽视的重要特性,在实时系统和高性能嵌入式应用中具有重要地位。

qq_43167806的博客 3329

STM32开发 -- 4G模块开发详解(1)

这部分一直再看,资料都已经整理好了,但是一直没有汇总。接下来就详细的看一下,GSM这部分是怎么实现的。

不积跬步,无以至千里 5万+

POJ 3006 Dirichlet's Theorem on Arithmetic Progressions

关于素数。

笨鸟 897

复现论文《基于Retinex理论和深度学习的低照度图像增强算法研究》

本研究提出两种基于Retinex理论和深度学习的低照度图像增强算法。第一种算法在HSV色彩空间中进行处理,采用Res2Block和CBAM-Res2block模块增强多尺度特征表示;第二种算法使用多尺度残差U型网络结构。复现代码展示了Res2Block、CBAM注意力机制等核心模块的实现,包括多尺度特征提取、通道和空间注意力机制。实验结果表明,所提算法能有效解决低照度图像存在的亮度低、对比度不足、颜色失真和细节丢失等问题,显著提升图像质量。

max500600的博客 389

poj 3006 Dirichlet's Theorem on Arithmetic Progressions

poj 3006 Dirichlet's Theorem onArithmetic Progressions Dirichlet's Theorem on Arithmetic Progressions Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 19133 Ac

emoheithree的博客 351

精雕软件(JDpaint) 5.5 绿色版

精雕软件(JDpaint) 5.5 绿色版精雕软件(JDpaint) 5.5 绿色版精雕软件(JDpaint) 5.5 绿色版

WINCC7.3破解文件

WINCC7.3硬件够破解文件,有需要的下载!WINCC7.3硬件够破解文件,有需要的下载!

poj3006 Dirichlet's Theorem on Arithmetic Progressions

Dirichlet's Theorem on Arithmetic Progressions Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 16333   Accepted: 8205 Description If a and d are relatively

Jinbao 793

RU DOS版、EFI版32bit/64bit BIOS常用工具

DOS版、EFI版的RU工具,可用来查看IO、MEM、PCI、SMBIOS等资源。亲测在EFI SHELL下可用。

POJ 3006 Dirichlet's Theorem on Arithmetic Progressions

POJ 3006http://poj.org/problem?id=3006 题目大意:找一个线性递增序列的第n个素数。 解题思路:直接搜嘛,线性复杂度O(n) AC代码: #include <iostream> #include <stdio.h> #include <cstring> #include <algorithm&...

Sensente的博客 215

锂电池充电器电路设计 里面有电路

锂电池充电器电路设计 里面有电路 3.7V升压到5V电路设计。

POJ 3006 Dirichlet's Theorem on Arithmetic Progressions

分析: 这道题要先用筛法求出10^6以内的素数。。。。我竟然觉得数据太多没用这种方式,然后写出来的代码就运行超时了,呜呜……最后还是用的筛法 Description If a and d are relatively prime positive integers, the arithmetic sequence beginning with a and increasing

my_adu的专栏 814

Dirichlet's Theorem on Arithmetic Progressions(POJ--3006

Description If a and d are relatively prime positive integers, the arithmetic sequence beginning with a and increasing by d, i.e., a, a + d, a + 2d, a + 3d, a + 4d, ..., contains infinitely many

zhang_di233的专栏 351

POJ3006,Dirichlet's Theorem on Arithmetic Progressions,狄利克雷定理,题目看懂就没什么

Dirichlet's Theorem on Arithmetic Progressions Description If a and d are relatively prime positive integers, the arithmetic sequence beginning with a and increasing by d, i.e., a, a + d, a + 2d,

/ 1926

Dirichlet's Theorem on Arithmetic Progressions POJ - 3006 线性欧拉筛

  题意 给出a d n 给出数列 a,a+d,a+2d,a+3d......a+kd 问第n个数是几 保证答案不溢出   直接线性筛模拟即可 1 #include<cstdio> 2 #include<cstring> 3 using namespace std; 4 bool Is_Primes[1000005];...

azmkinbug41973327的博客 204

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

Dirichlet's Theorem on Arithmetic Progressions Time Limit:1000MS Memory Limit:65536K Total Submissions:13636 Accepted:6808 Description Ifaanddare relativ...

anvt77205的博客 142

POJ 3006 Dirichlet's Theorem on Arithmetic Progressions G++

#include <iostream> using namespace std; int prim[1000008]; int main() { prim[1]=1; prim[0]=1; for(int i=2;i<1000000;i++) { if(prim[i]==0) for(int j=2;j*i<1000000;j++) { ...

woniupengpeng的专栏 148
上一篇: poj1503Integer Inquiry
下一篇: poj2255Tree Recovery(二叉树,递归)
luckcircle
博客等级 码龄10年 13粉丝 50原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值