codeforces 937B Vile Grasshoppers

【可不卸载重装】VS2019新建项目里没有CUDA选项 问题:VS2019 新建项目里没有CUDA选项,vs也属性没有cuda。这是因为你在Visual Studio 2019安装之前,先安装了CUDA Toolkit。 阅读详情

http://www.elijahqi.win/2018/02/26/codeforces-937b-vile-grasshoppers/ ‎

The weather is fine today and hence it’s high time to climb the nearby pine and enjoy the landscape.

The pine’s trunk includes several branches, located one above another and numbered from 2 to y. Some of them (more precise, from 2 to p) are occupied by tiny vile grasshoppers which you’re at war with. These grasshoppers are known for their awesome jumping skills: the grasshopper at branch x can jump to branches .

Keeping this in mind, you wisely decided to choose such a branch that none of the grasshoppers could interrupt you. At the same time you wanna settle as high as possible since the view from up there is simply breathtaking.

In other words, your goal is to find the highest branch that cannot be reached by any of the grasshoppers or report that it’s impossible.

Input
The only line contains two integers p and y (2 ≤ p ≤ y ≤ 109).

Output
Output the number of the highest suitable branch. If there are none, print -1 instead.

Examples
Input

Copy
3 6
Output
5
Input

Copy
3 4
Output
-1
Note
In the first sample case grasshopper from branch 2 reaches branches 2, 4 and 6 while branch 3 is initially settled by another grasshopper. Therefore the answer is 5.

It immediately follows that there are no valid branches in second sample case.

全场这题被坑了很久 但是后来想想因为1e9之内素数有5e7 所以平均不超过100个 就可能有答案 直接从最高位开始暴力枚举即可 注意判断一下这个因数是否小于等于p

#include<cmath>
#include<cstdio>
int p,y;
int main(){
//  freopen("b.in","r",stdin);
    scanf("%d%d",&p,&y);
    int ans=0;
    while(y>p){
        bool flag=0;
        for (int i=2;i<=sqrt(y);++i){
            if ((y%i==0)&&i<=p) {flag=1;break;}
        }if (!flag) {ans=y;break;}y--;
    }if (!ans) puts("-1");else printf("%d\n",ans);
    return 0;
}
【GameFramework框架内置模块】6、实体(Entity) 实体Entity就是一个实体的基本单元,类似于Unity的GameObject对象本体,然后这个本体上面附加其他各种各样组件,才能实现各种各样的功能。一般需要在游戏运行时动态加载的游戏对象,比如怪物、武器、子弹、特效,都需要给这个物体挂载一个实体Entity,这样的话就可以方便的对实例出来的对象进行管理。下面就来看一下如何使用吧。 阅读详情

相关推荐

AD20丝印层导入图片logo保姆级教程(附黑白预览避坑技巧)

本文提供了一份详尽的AD20丝印层导入图片Logo的实战指南。核心在于将图片预处理为高质量的单色BMP位图,并独家分享了利用Windows画图工具进行“黑白预览”的关键技巧,以提前规避转换失真。教程涵盖了从脚本获取、图片处理、参数设置到生产规范的完整流程,帮助硬件工程师高效、准确地在PCB的Top Overlay层添加个性化标识。

weixin_29194255的博客 394

最小质因数——埃式筛法

观测输入组数 和数字的大小 普通的素数判断方法就显得力不从心了 利用数学的性质,就可以很好的解决该问题 整体思路是抓奇数 然后对奇数进行翻倍 原理是:奇数的倍数 一定不是质数 所以每个奇数的倍数可以 将每个非质数的数都赛选出来 如果没有筛到的数 那就一定是质数 所以 开头写一个循环 让每个数等于自己的本身 //对奇数的倍数j进行筛出 // 那么i一定是j的因子 // 但是 3 9 都是18的因子 // 所以一定要保存最小的因子 // 题目要求的是 质因子 问题来了 ,如何判定i是不是质数呢?.

摸鱼博客 5164

YOLO11实战 第056期-基于yolo11的无人机航拍铁路障碍物检测实战-数据集&源码&系统

召回率曲线帮助评估模型在目标检测任务中,检测到真正目标的能力。通过这条曲线,可以评估模型在目标检测任务中的整体性能,并找到合适的置信度阈值,以在精确率和召回率之间做出最佳平衡。PR曲线越接近右上角,模型性能越好,曲线下方的面积越大,说明模型在不同置信度下的。这条曲线显示了随着置信度的增加,每个类别的召回率先变化较小,然后在某个点之后迅速下降。通过这条曲线,可以选择合适的置信度阈值,以优化模型的检测结果,平衡精确率和召回率。曲线都显示了随着召回率的增加,精确度略有下降的趋势,但整体上精确度保持在很高的水平。

深度学习算法工程师,专注于前沿算法研究与实战应用。在这里,我将分享深度学习领域的实战经验、优质数据集资源以及最新论文解读与精度分析,旨在与广大技术爱好者共同探索人工智能的奥秘,助力技术成长与创新。 166

关于最小质因子

题目链接 所有不是质数的数的最小质因子是2或3或5或7。 题解:1,如果n是素数,那么n-n=0执行一次减法。,2,如果n是合数,那么它的最小素因子要么是2要么3要么5要么7,再细分如果n是偶数则它的最小素因子是2,如果n是奇数,它的最小素因子是3/5/7,但无论如何此时的n减去它的最小素因子都是偶数,偶数的最小素因子是2,偶数减2还是偶数,所以对于这种情况只需找出n的最小素因子x,然后让n减去它...

weixin_45502089的博客 7309

告别两个电源模块!用UCD3138+四开关Buck-Boost,一个电路搞定电池充放电(附原理图分析)

本文详细介绍了采用UCD3138数字控制器和四开关Buck-Boost拓扑的双向DC/DC变换器设计,实现单一电路完成电池智能充放电管理。该方案显著降低BOM成本和PCB面积,提升系统效率至96.2%,适用于UPS、通信基站和储能系统,具有高效、紧凑和成本优势。

weixin_30256901的博客 404

08-SD卡-TF卡硬件电路设计

SD卡-TF卡硬件电路设计

weixin_66510961的博客 8287

25-最小质因子之和

博主备考练习题

月亮被咬碎成星星的博客 501

【Python&RS】哨兵2号(Sentinel2)轨道条带说明+图幅统计(表格+矢量)

今天给大家带来哨兵2号的图幅编号介绍以及全国省、市所需图幅数的统计。网上教程极少,而且结果也不公开。因为每次下载的时候都不知道需要几幅,所以研究后给大家分享一下。

Remote Sensing迷途小书童 1704

最小质因子之和

线性筛的思想是让每个合数只被其最小质因数筛去一次,这里对于每个素数,筛去其不小于其平方,不大于上界的所有倍数。4、即同一个数仍然有可能被重复选中,仅在其未被筛过(最小质因数为初始值)时将其最小质因数赋值为该素数。每个数最小质因数的算法,然后对于重复的查询质因数之和只需要用前缀和维护确定直接输出即可。3、在素数条件下,将不小于其平方,不大于上界的所有倍数标记。2、循环中未被标记的数为素数,显然其最小质因数为本身。1、首先初始化判断素数列表为真,最小质因数列表为0。并计算存储其前缀和。每个数的最小质因数之和。

当个免费仓库用用 332

Arduino、ESP32驱动TEMT6000传感器(光照传感器篇)

TEMT6000是一个三极管类型的光敏传感器,其光照强度和基极的电流成正比。用起来也相当简单,可以简单的连接该传感器的基极到模拟电压输入,通过简单的检测电压值就可以判断当前的光照强度。

不脱发的程序猿 4255

Android PMS——概述(一)

PMS(Package Manager Service)是 Android 操作系统的一个重要组件,它负责管理应用程序的包信息以及与应用程序的安装、卸载、权限控制等相关功能,确保应用程序的安全性和稳定性。 Android PMS 负责维护一个应用程序包的清单信息,该清单是一个 XML 文件,包含应用程序的各种元数据,例如应用程序的包名、版本号、权限要求、组件信息等。PMS通过访问该清单文件来获取应用程序的信息。 此外,Android PMS 还负责应用程序的安装和卸载。在安装应用

小旭的专栏 1690

CF937B Vile Grasshoppers

Vile Grasshoppers time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output The weather is fine today and hence it's h...

weixin_34189116的博客 188

迈瑞BS系列全自动生化分析仪LIS协议接口手册(内含HL7和ASTM)

迈瑞BS系列全自动生化分析仪LIS协议接口手册,内含HL7和ASTM)

codeforces 937B Vile Grasshoppers

The weather is fine today and hence it's high time to climb the nearby pine and enjoy the landscape.The pine's trunk includes several branches, located one above another and numbered from 2 to y. Some...

Andromeda_Galaxy的博客 586

pscad IEEE标准系统搭建说明

pscad IEEE标准系统搭建说明,包含典型的IEEE 9节点、14节点、30节点、39节点和118节点系统。内含标准测试系统的原始数据和潮流结果。

win10 跳过U8环境检测的IE WebControls.rar

win10 安装u8的时候 提示IE WebControls 不通过,这个工具可以欺骗u8的检查。 跳过U8环境检测的IE WebControls。提示导入失败后,重新检测通过。

CodeForces 937B Vile Grasshoppers【math 超时】

B. Vile Grasshoppers time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard output The weather is fine today and hence it’s high time to climb the nearb...

肖火柴的火柴盒 270

深度学习工具包 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")

Codeforces 937B Vile Grasshoppers

The weather is fine today and hence it's high time to climb the nearby pine and enjoy the landscape.The pine's trunk includes several branches, located one above another and numbered from 2 to...

包子不卖包子 553

Vile Grasshoppers CodeForces - 937B

                                 Vile GrasshoppersThe weather is fine today and hence it's high time to climb the nearby pine and enjoy the landscape.The pine's trunk includes several branches, locate...

MengX 309

【Codeforces】937 B. Vile Grasshoppers 数学、细节

http://codeforces.com/contest/937/problem/B 给两个数 p, y; 求 p到y的区间中 不是2到p之间的倍数的最大数 #include &lt;iostream&gt; #include &lt;queue&gt; #include &lt;map&gt; #include &lt;cstring&gt; using namespace std; ...

西瓜不甜的博客 258

Vile Grasshoppers CodeForces - 937B(枚举最小质因数)

The weather is fine today and hence it’s high time to climb the nearby pine and enjoy the landscape. The pine’s trunk includes several branches, located one above another and numbered from 2 to y. Som...

tomjobs的博客 381

Codeforces 937.B Vile Grasshoppers

B. Vile Grasshoppers time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output The weather is fine today and hence it's h...

weixin_30381793的博客 129

源哥每日一题第五弹 Codeforces 937B Vile Grasshoppers

题目链接:http://codeforces.com/problemset/problem/937/B题意:求(p,y]中,不是[2,p]之间数的倍数的最大数思路:最暴力的想法:从最大的数一定在y和y之前的一个素数之间;但是按常理来讲,这样的方法太暴力了,无法满足时间限制——真的是这样么?伟大的数学家们帮助我们解决了这个问题:素数之间的间隔是多少呢?对小于7.263x10^13的所有相邻素数的间隔...

风语之城的博客 243

Codeforces937 B. Vile Grasshoppers(素数距离性质)

题意: 给定p和y,把[2,p]中每个数都标记,问[p+1,y]中未被标记的最大值 无解则输出-1 数据范围:p,y<=1e9 解法: 显然最大值的质因子都不在[2,p]中,那么用质因子check某个值是否被标记 但是数据范围很大,有1e9,看起来无法全部枚举 但实际上有个结论: <=1e9的两个质数之间的差不超过300,所以从y倒着暴力枚举即可 code: #include<bits/stdc++.h> using namespace std; signed main(){

zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz 280

B - Vile Grasshoppers (codeforces)

The weather is fine today and hence it’s high time to climb the nearby pine and enjoy the landscape. The pine’s trunk includes several branches, located one above another and numbered from 2 to y. Som...

qq_43605752的博客 194

Codeforces - Vile Grasshoppers

The weather is fine today and hence it’s high time to climb the nearby pine and enjoy the landscape. The pine’s trunk includes several branches, located one above another and numbered from 2 to y. Som...

青烟绕指柔的博客 336

Codeforces Round #467 (Div. 2) B. Vile Grasshoppers

B. Vile GrasshoppersThe weather is fine today and hence it's high time to climb the nearby pine and enjoy the landscape.The pine's trunk includes several branches, located one above another and number...

s540239976的博客 518

Codeforces #467 (Div. 2) B. Vile Grasshoppers ( 数学

B. Vile Grasshoppers 题目描述 The weather is fine today and hence it’s high time to climb the nearby pine and enjoy the landscape. The pine’s trunk includes several branches, located one above another...

Yishui_lovely 728

Codeforces #467 (Div. 2) B. Vile Grasshoppers 蚂蚱的题目

zj讲了半天,我什么都没听懂,我只是想自己看看我就能明白吧,我?哈哈哈,高数作业还没写,算法课要不要上http://blog.csdn.net/wang2332/article/details/79373271**题意有点重要,其实也就是从2到p这些数字,按倍数往后算吧,直到跳不到,界限 是y那么也就是说有个素数的话,肯定大于素数,因为素数是肯定满足题意的,那个跳不到的点如果由于p的原因并不是素数...

lx233 244
上一篇: codeforces 937A Olympiad
下一篇: codeforces 936B Sleepy Game
elijahqi
博客等级 码龄9年 55粉丝 1280原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值