技术好文:VileGrasshoppers

简介: 技术好文:VileGrasshoppers

"

Problem description

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 //代码效果参考:https://v.youku.com/v_show/id_XNjQwMDE4NDEzNg==.html

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 -1instead.

Examples

Input

3 6

3 4

Output

5

-1

Note

In the first sample case grasshopper from branch 2 reaches branches 2, 4 and 6 while branch 3 is initially settled by //代码效果参考:https://v.youku.com/v_show/id_XNjQwMDE4NDE1Mg==.html

another grasshopper. Therefore the answer is 5.

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

解题思路:给两个数 p,y,求区间(p,y】中不是【2,p】之间的倍数的最大数,明显可知如果存在这个数,那么它一定是不大于y的最大素数。因为在2~1e9的范围内相邻素数之差最大不超过1e3,所以最坏的时间为1e3?sqrt(1e9)≈1e7,可以A过。

AC代码:

1 #include [/span>bits/stdc++.h

2 using namespace std;

3 int p,y;bool flag=false;

4 bool isprime(int x){

5 for(int i=2;i*i<=x&&i<=p;++i)//注意最大因子至多为p

6 if(x%i==0)return false;

7 return true;

8 }

9 int main(){

10 cinpy;

11 for(int i=y;i

12 if(isprime(i)){flag=true;cout[i[endl;break;}

13 if(!flag)cout[""-1""[endl;

14 return 0;

15 }

作者:霜雪千年

出处:

本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须在文章页面给出原文连接,否则保留追究法律责任的权利。


"
image.png
相关文章
|
7月前
|
Linux API Apache
技术好文:saltstackpillar
技术好文:saltstackpillar
34 1
|
7月前
|
存储 编解码 索引
技术好文:StudingDay3
技术好文:StudingDay3
|
7月前
|
API C#
技术好文:xluatips
技术好文:xluatips
28 0
|
7月前
|
前端开发
技术好文:wobble
技术好文:wobble
35 0
|
8月前
好文推荐
好文推荐
187 2
|
7月前
|
JSON 程序员 Swift
技术好文:Swit项目
技术好文:Swit项目
37 0
|
7月前
|
前端开发 关系型数据库 MySQL
技术好文:R基础学习(三)
技术好文:R基础学习(三)
36 0
|
消息中间件 安全 Java
全网首发!消息中间件神仙笔记,涵盖阿里十年技术精髓
消息中间件是分布式系统中的重要组件,在实际工作中常用消息中间件进行系统间数据交换,从而解决应用解耦、异步消息、流量削峰等问题,实现高性能、高可用、可伸缩和最终一致性架构。
|
存储 前端开发 JavaScript
十五分钟读懂React 17 | 🏆 技术专题第六期征文
作为时下最火的前端框架之一,React每次发版都会带来创新的改变,如React最早提出虚拟DOM、React 16引入fiber架构,再到后来React 16.8提出令人耳目一新的Hooks,这些创新也是很多人推崇React的一个重要原因。然而,到了React 17,rc发布日志上竟然说这次版本最大的特点就是无新特性,从目前来说,这个日志是让很多人失望了。
386 0
|
机器学习/深度学习 算法 搜索推荐
一次看完2019技术好文,快收藏!
​2019 即将过去。在今年的最后一天,阿里机器智能献上全年文章汇总。在你遇到技术问题的时候,希望这些内容能够为你提供些许帮助。 2019 感谢有你相伴,2020 我们继续携手前行。
17109 0
一次看完2019技术好文,快收藏!

热门文章

最新文章