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, 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: 16333 Accepted: 8205

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,差值b,问在等差数列中第n个素数是哪个?

#include <iostream>
#include <string.h>
using namespace std;
bool isprime(int n){
	if (n<2)
		return false;
	if (n==2 || n==3 || n==5 || n==7)
		return true;
	for (int i=2;i*i<=n;i++)
		if (n%i==0)
			return false;
	return true;
}
int main(){
	int a,b,n;
	while (cin>>a>>b>>n){
		if (a==0&&b==0&&n==0)
			break;
		int num=1,sum;
		for (int i=0;num<=n;i++){
			sum=a+b*i;
			if (isprime(sum)==true)
				num++;
		}
		cout<<sum<<endl;
	}
	return 0;
}



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

相关推荐

cpp中auto, auto &和const auto &的区别

笔者初学cpp,如有纰漏,请见谅并指正。 用在哪 auto用于推断类型,具体可用于声明变量时根据初始化表达式自动推断该变量的类型,也就是可用在for循环。 也可以用于声明函数返回值的占位符。 怎么用 这里主要讲for循环中三者的区别 直接说结论 auto auto用于copy一份集合中的数据,对于这种情况,在循环体中不论怎么修改copy的数据,是不会影响到原有集合中的数据的。 举个简单的例子 int arr[5] = {0, 1, 2, 3, 4}; cout << "使用auto" <&

NinoSun的博客 3175

杂记

做了一道编程题:找素数设一个等差数列,首元素为367,公差为186, 现在要求找出属于该等差数列中的第151个素数并输出。格式:CTF{xxx}源码如下(python 3):import math def panduan(a): for x in range(2, int(math.sqrt(a) + 1)): if a % x == 0: retu...

h1012946585的博客 1112

LCD驱动芯片——BL55072A驱动程序

初始化子程序: START 0x7C; I2C子地址 0xEA;ICSET,软件复位芯片 0xC0;MODSET,关显示 0xF0;BLKCTL,关闪烁 0xA3;DISCTL,80Hz Line inversion,High Power mode 0xE8;ICSET,清复位bit1 STOP 显示刷新子程序: START 0x7C;I2C子地址 0xF0;BLKCTL,关闪烁 0xA3;DISCTL,80Hz Line inversion,High Power mode 0xE8或0xEC;ICSE

love421的博客 3175

POJ 3006 Dirichlet's Theorem on Arithmetic Progressions(我的水题之路——加i个d后的第几个素数)

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

842

NVIDIA驱动版本太低?手把手教你解决CUDA与PyTorch版本冲突问题

本文针对深度学习开发中常见的NVIDIA驱动版本过低导致的CUDA与PyTorch版本冲突问题,提供了从根源理解到实战解决的完整指南。文章详细解析了驱动、CUDA与PyTorch的依赖关系,并给出了升级驱动、降级PyTorch、使用Conda环境管理及Docker容器化四种核心解决方案,帮助开发者快速诊断并构建稳定的GPU开发工作流。

grpc6streamer的博客 968

MobaXterm-SSH远程连接Ubuntu

我们常常在公司的服务器上面的虚拟机进行交叉编译,所以才需要我们用远程终端工具MobaXterm去接入虚拟机。然后把我们在window用VScode编辑好的代码拖拽上传到服务器,等待服务器编译完把生成的可执行文件从服务器拖拽下来,烧录到板子运行。

weixin_50257954的博客 3471

实验吧编程 -找素数

链接:http://www.shiyanbar.com/ctf/1922 设一个等差数列,首元素为367,公差为186, 现在要求找出属于该等差数列中的第151个素数并输出。 python代码: def prime(a):    #判断a是否是素数 for i in range(2,a): if (a % i) == 0: retur...

weixin_30667649的博客 169

手机安装Kali Linux

在数字化时代,信息安全和隐私保护显得尤为重要。,作为一款专业的和工具,因其强大的功能和丰富的资源库而受到广大安全研究者和爱好者的青睐。然而,我们通常只能在传统的电脑设备上安装和使用Kali Linux。那么,有没有可能将也变成一款随身携带的Kali Linux设备呢?答案是肯定的。本文将介绍如何在手机上安装Kali Linux,使你的手机变成一款强大的移动安全工具。,我们需要明确一点,手机安装Kali Linux并非简单的操作,需要对手机进行一定的改造和配置。

2301_80124151的博客 6964

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

我装了10个ClawHub技能,这些最好用!

ClawHub就是Clawdbot的"应用商店"。Clawdbot是手机ClawHub是App Store技能就是各种App装了技能,Clawdbot才能干更多事。这个技能解决了我的信息过载问题。为什么装我订阅了很多Newsletter。每天收到一堆长文章,根本看不完。怎么用“总结这篇文章的核心观点”“把这个Newsletter提炼成3个要点”“这篇技术博客有哪些可以实践的建议?安装命令真实体验现在我收到长文章,直接转发给Clawdbot。它会提炼出核心要点和行动清单。

Maynor的博客 6099

基于Simulink的锂电池热模型与温控管理仿真

本文完成了基于Simulink的锂电池热模型与温控管理仿真,实现了:✅ 建立电-热耦合产热模型✅ 构建集总参数热网络✅ 设计基于迟滞的风扇启停控制✅ 验证在高倍率工况下的有效温控能力✅ 为实际电池热管理系统(BTMS)提供设计原型。

xiaoheshang_123的博客 149

POJ 3006 Dirichlet's Theorem on Arithmetic Progressions

关于素数。

笨鸟 897

ESP32设备驱动-TB6612FNG直流电机驱动

TB6612FNG 是一款出色的双电机驱动器,非常适合将两个小型直流电机(例如微型金属齿轮电机)连接到微控制器,它还可以用于控制单个双极步进电机。 基于 MOSFET 的 H 桥比 L298N 和 Sanyo 的 LB1836M 等旧式驱动器中使用的基于 BJT 的 H 桥效率高得多,后者允许将更多电流输送到电机,而从逻辑电源汲取的电流更少 (对于真正低电压的应用,LB1836 仍然具有 TB6612 的优势)。

视觉与物联智能 3401

POJ 3006 Dirichlet's Theorem on Arithmetic Progressions

/**//************************************** Problem:POJ3006Dirichlet'sTheoremonArithmeticProgressions Time:79MS Memory:1180K AcceptedTime:2009-05-1710:41:54 Tips: *****************...

weixin_30361641的博客 61

C# WinForm 基于DirectShow.dll编写的程序,可边预览边保存视频,音频和图片

基于微软的DirectShow.dll的二次开发1.自动识别连接的摄像头跟麦克风且可以对其进行选择(默认选中第一个)2.可录制wmv和avi两种格式的视频并且都带有音频,avi可以录制的分辨率和帧数进行选择,wmv默认进行了淸晰度优化如不喜欢可去除代码中有相关提示3.可在预览点开之后进行拍照,也可边录制视频边拍照4.添加了视频和音频的压缩功能(酌情使用)这次二次开发发现C#对DirectShow的相关信息太少,这次做完也不敢藏私共享出来,还望大家指正

Data-Structures-and-Algorithm-Analysis-in-Java.pdf

作者: Weiss, Mark A. 出版社: Addison Wesley Data Structures and Algorithm Analysis in Java is an “advanced algorithms” book that fits between traditional CS2 and Algorithms Analysis courses. In the old ACM Curriculum Guidelines, this course was known as CS7. This text is for readers who want to learn good programming and algorithm analysis skills simultaneously so that they can develop such programs with the maximum amo...

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

jdk-8u144-linux-x64.tar.gz.

该资源为搭建Linux系统Java环境用,资源的后缀为tar.gz格式的压缩包

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

VB摄像头监控

该VB模块可对摄像头捕获的画面进行录像等,可在创建的窗口进行控制

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

。。今晚练习简直就是模板测试专题,又测了两个质数模板,,发现线性筛的那个模板弄错了,,于是改了一下,修正过来了 因为这题已经告诉你了答案不会超过1e6,所以就把1e6的质数全部筛选出来,就可以通过O(1)方法判断是否是质数,然后暴力枚举质数个数就可以了 #include #include #include #include #include #include #include usi

qwb的博客 919

POJ 3006 - Dirichlet's Theorem on Arithmetic Progressions

Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 15148   Accepted: 7592 Description If a and d are relatively prime positive integers, the arithmetic sequence beginnin

Latte_z的小站 540

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
上一篇: poj1083 Moving Tables
下一篇: poj2255 Tree Recovery
JinbaoSite0144
博客等级 码龄12年 231粉丝 157原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值