首页 技术 正文
技术 2022年11月15日
0 收藏 519 点赞 4,616 浏览 1470 个字

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 CodeForces937B:Vile Grasshoppers(素数性质).

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.

Examplesinput

3 6

output

5input

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.

题意:给定P和Y,求最大的X,满足<=Y,且不是2到P的倍数。

思路: 没想到是暴力求解。。。这里利用了一个性质,1e9范围内相邻的素数距离不超过300。所以我们从Y向下验证是否是“素数”,这里的素数指的的无[2,P]区间的因子。可以想象,由于可以除的数少了,这些“素数”的距离比300更加接近,而检验素数的复杂度不超过根号。于是复杂度<O(300*sqrt(1e9));

#include<bits/stdc++.h>
using namespace std;
int P,Y;
bool isprime(int x){
for(int i=;i<=P&&i*i<=x;i++){
if(x%i==) return false;
} return true;
}
int main()
{
scanf("%d%d",&P,&Y);
for(int i=Y;i>P;i--){
if(isprime(i)) {
printf("%d\n",i);
return ;
}
}
printf("-1\n");
return ;
}
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:8,982
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,499
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,343
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,126
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,760
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,796