poj 3006 Dirichlet's Theorem on Arithmetic Progressions

配置VS Code使用Linux服务器上的Matlab 0、需求 Linux服务器上安装有Matlab 无图形界面,只能使用命令行工具,编辑文件不方便 1、VS Code插件安装 在扩展商店中搜索matlab,会出现Matlab Extension Pack,里面有整理好的matlab扩展 这里只安装了第一排的三个扩展 2、设置(Windows、Mac的设置类似,只是不同系统的文件路径不同) 安装好扩展,重启VS Code后,进行设置 打开:文件→首选项→设置(或快捷键ctrl+,),搜索matlab,结果如下图所示;直接打开完整json配置文件(图 阅读详情

poj 3006 Dirichlet's Theorem onArithmetic Progressions

Dirichlet's Theorem on Arithmetic Progressions

Time Limit: 1000MS

Memory Limit: 65536K

Total Submissions: 19133

Accepted: 9609

Description

If a and d arerelatively prime positive integers, the arithmetic sequence beginningwith 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'sTheorem on Arithmetic Progressions, which had been conjectured by Johann CarlFriedrich Gauss (1777 - 1855) and was proved by Johann Peter Gustav LejeuneDirichlet (1805 - 1859) in 1837.

For example, thearithmetic 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, ... ,

containsinfinitely 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 nthprime number in this arithmetic sequence for given positive integers a, d,and n.

Input

The input is asequence of datasets. A dataset is a line containing three positiveintegers a, d, and n separated by aspace. a and d are relatively prime. You mayassume a <= 9307, d <= 346, and n <=210.

The end of theinput is indicated by a line containing three zeros separated by a space. It isnot a dataset.

Output

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

The output integercorresponding to a dataset a, d, n shouldbe the nth prime number among those contained in the arithmeticsequence beginning with a and increasing by d.

FYI, it is knownthat the result is always less than 106 (one million) underthis 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

 

 

 

 

涉及素数的题目貌似没有什么好办法,直接打印素数用的时候再取出来即可。

打表参考:http://blog.youkuaiyun.com/dinosoft/article/details/5829550

 

代码:

//poj 3006 Dirichlet's Theorem on Arithmetic Progressions
#include <cstdio>
#include <cstring>
constint max=1000500;
bool is_prime[max];
int prime[max];
int top=0;
void intitPrime(){
    memset(is_prime,true,sizeof is_prime);
    for(int i=2; i<max; i++){
       if(is_prime[i])
            prime[top++]= i;
       for(int j=0; j<top&&i*prime[j]<max; j++){
            is_prime[i*prime[j]]=false;
           if(i%prime[j]==0)break;
       }
    }
}
 
int main(int argc,charconst*argv[])
{
    intitPrime();
    freopen("in.txt","r", stdin);
    int a, b, n;
    while(scanf("%d %d%d",&a,&b,&n)!= EOF &&(a| b| n)){
       int i;
       for(i= a; i< max&&n>0; i += b){
           if(is_prime[i]) n--;
       }
        printf("%d\n", i);
    }
    return0;
}

 

使用verilog实现基于FPGA的TDC设计 verilog实现TDC 高精度时间数字转换器概述(TDC) 简介: TDC被用于测量时间间隔,应用在物理研究、飞行时间测量领域等。 本设计使用verilog实现并在xilinx和altera的FPGA上均可实现! 设计中使用到下述几个模块,包括FIFO,COUNT等,在xilinx下也使用到了一些原语等。下面有实现的代码和仿真截图等。 顶层模块设计如下: module top( input wire start, input wire stop, input wire clk, output wire T 阅读详情

相关推荐

用R搞定生态溯源:MixSIAR贝叶斯混合模型从安装到出图的保姆级教程

本文提供了一份详细的MixSIAR贝叶斯混合模型教程,涵盖从R环境配置、数据预处理到模型参数设置和可视化分析的完整流程。通过实战案例和常见问题解决方案,帮助生态学研究者快速掌握混合模型在生态溯源中的应用,提升数据分析效率。

weixin_42531516的博客 466

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

程序设计二(面向对象)_实训10_复杂类的实现_ArrayList类的实现

第1关:构造函数与析构函数的实现

2401_83406306的博客 819

POJ 3006 Dirichlet's Theorem on Arithmetic Progressions

关于素数。

笨鸟 897

ERDAS 2022与ArcGIS共存安装教程:如何避免端口冲突(详细配置步骤)

本文提供了一份详细的ERDAS 2022与ArcGIS共存安装教程,核心在于解决两者因FlexNet许可证服务器导致的端口冲突问题。通过分步指导,包括检查现有端口占用、修改ERDAS许可证文件端口号、配置防火墙及客户端设置,确保两款专业GIS与遥感软件能在同一系统上稳定运行。

weixin_29279047的博客 253

深度强化Q学习-基于微软AirSim仿真环境的自动驾驶案例(原理代码详解简易可行)

最近在学习《强化学习原理与Python实现》,肖智清著。参考第十二章的自动驾驶案例,写一篇总结,尽量做到简单可行,让有志于自动驾驶的小伙伴可以通过此篇博客可以管中窥豹,初步了解自动驾驶的强化学习训练过程。 本篇将自动驾驶问题转化为回合制的强化学习任务,设计以车辆观察图像和运行状态为输入的自动驾驶算法,并在AirSim仿真环境中进行训练和测试。本篇使用带经验回放和目标网络的基于深度Q网络算法设计并实现智能体,对经验回放、目标网络和深度Q学习算法进行简单介绍,并用代码实现。

shao918516的博客 8599

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

2024年全国青少年信息素养大赛初赛真题(算法创意实践挑战赛C++小学组:带解析)

2024全国青少年信息素养大赛C++算法创意实践挑战赛初赛真题及解析

王老师青少年编程 2807

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

自然语言处理之机器翻译:Transformer:Transformer在低资源语言翻译中的应用

Transformer模型是自然语言处理领域的一个重要突破,由Vaswani等人在2017年的论文《Attention is All You Need》中提出。它摒弃了传统的循环神经网络(RNN)和卷积神经网络(CNN)的序列依赖性,采用自注意力机制(Self-Attention)处理输入序列,极大地提高了训练效率和模型性能。

zhubeibei168的博客 1014

ABAP Channels 之 WebSocket 通信实践:用 ABAP Push Channel 打造实时应用

摘要:本文介绍了ABAP Push Channel(APC)技术,它通过WebSocket协议实现ABAP系统与外部客户端的实时双向通信。文章对比了传统HTTP轮询与WebSocket的差异,解释了APC的事件模型及其接口演进(从IF_APC_WS_EXTENSION到IF_APC_WSP_EXTENSION)。通过仓库拣货等实际案例,展示了APC在企业级应用中的价值,如实时监控、协作场景等。文中还详细阐述了ABAP引擎中WebSocket的交互模型,说明其资源优化设计原理,并提供了基础代码示例。该技术解决

2007 年 ~ 2025 年,深耕 SAP 技术 18 年 293

POJ3006-Dirichlet's Theorem on Arithmetic Progressions

全解题报告索引目录 -> 【北大ACM – POJ试题分类】 转载请注明出处:http://exp-blog.com ------------------------------------------------------------------------- 题目大意 狄利克雷基于等差数列的算法原理 设一个等差数列,首元素为a,公差为b 现在要求输入a,b,n ,要求...

ζёСяêτ - 小優YoU 3552

三维点云转深度图

点云投影过程是将三维点云数据转化为二维图像坐标的关键步骤,它的实现涉及到相机内外参数的计算,包括相机的内部参数(如焦距和主点)和外部参数(如相机位置和方向)。具体来说,可以通过将每个点的三维坐标转换为相机坐标系下的坐标,然后使用相机内部参数和外部参数来计算在二维图像中的坐标。接着计算每个点的深度值,将深度值映射到像素值上,最后创建深度图像并将深度值赋给对应的像素值。这里需要注意的是,在将深度值映射到像素值上时,需要将像素值转换为 uchar 类型,否则在将深度值赋给像素值时会出现类型不匹配的错误。

点云兔子的博客 3171

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

汉书HE8,好用的汇编代码编写工具

汉书HE8,好用的汇编代码编写工具早期编写汇编代码所用功能强大

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

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

质数筛选 poj3006 Dirichlet's Theorem on Arithmetic Progressions

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

qwb的博客 919

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

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

poj3006——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 man

Beyond the Sora 958

POJ - 3006:Dirichlet's Theorem on Arithmetic Progressions

Ifaanddare relatively prime positive integers, the arithmetic sequence beginning withaand increasing byd, i.e.,a,a+d,a+ 2d,a+ 3d,a+ 4d, ..., contains infinitely many prime numbers. Th...

weixin_37992828的博客 158

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

POJ--3006 Dirichlet's Theorem on Arithmetic Progressions

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

社畜のブログ 421
上一篇: POJ – 1503 Integer Inquiry Integer Inquiry
下一篇: POJ 2255 Tree Recovery
朔北冥
博客等级 码龄11年 14粉丝 27原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值