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 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 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代码:

 #include <bits/stdc++.h>
using namespace std;
int p,y;bool flag=false;
bool isprime(int x){
for(int i=;i*i<=x&&i<=p;++i)//注意最大因子至多为p
if(x%i==)return false;
return true;
}
int main(){
cin>>p>>y;
for(int i=y;i>p;--i)
if(isprime(i)){flag=true;cout<<i<<endl;break;}
if(!flag)cout<<"-1"<<endl;
return ;
}

A - Vile Grasshoppers的更多相关文章

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

    2018-03-03 http://codeforces.com/problemset/problem/937/B B. Vile Grasshoppers time limit per test 1 ...

  2. B. Vile Grasshoppers

    http://codeforces.com/problemset/problem/937/B The weather is fine today and hence it's high time to ...

  3. Codeforces 937.B Vile Grasshoppers

    B. Vile Grasshoppers time limit per test 1 second memory limit per test 256 megabytes input standard ...

  4. Codeforces Round #467 (Div. 2) B. Vile Grasshoppers[求去掉2-y中所有2-p的数的倍数后剩下的最大值]

    B. Vile Grasshoppers time limit per test 1 second memory limit per test 256 megabytes input standard ...

  5. CodeForces937B:Vile Grasshoppers(素数性质)

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

  6. CF937B Vile Grasshoppers

    Vile Grasshoppers time limit per test 1 second memory limit per test 256 megabytes input standard in ...

  7. Codeforces Round #467 (div.2)

    Codeforces Round #467 (div.2) 我才不会打这种比赛呢 (其实本来打算打的) 谁叫它推迟到了\(00:05\) 我爱睡觉 题解 A. Olympiad 翻译 给你若干人的成绩 ...

  8. codeforce round #467(div.2)

    A. Olympiad 给出n个数,让你找出有几个非零并且不重复的数 所以用stl的set //#define debug #include<stdio.h> #include<ma ...

  9. 【codeforces】【比赛题解】#937 CF Round #467 (Div. 2)

    没有参加,但是之后几天打了哦,第三场AK的CF比赛. CF大扫荡计划正在稳步进行. [A]Olympiad 题意: 给\(n\)个人颁奖,要满足: 至少有一个人拿奖. 如果得分为\(x\)的有奖,那么 ...

随机推荐

  1. IT狂人职场路:揭秘华为百度高管如何炼成?

    原文链接:http://www.hdeso.com/waibao/detail.asp?id=45660 原文链接:http://tech.hexun.com/2014-02-18/162264716 ...

  2. 【JSP】常用跳转方式

    原文地址:http://blog.csdn.net/wanghuan203/article/details/8836326 (1)href超链接标记,属于客户端跳转 (2)使用javascript完成 ...

  3. Ubuntu 16.04安装和卸载软件命令

    安装软件 apt-get install softname1 softname2 softname3…… 卸载软件 apt-get remove softname1 softname2 softnam ...

  4. Vue: axios 请求封装及设置默认域名前缀 (for Vue 2.0)

    1. 实现效果 以get方法向http://192.168.32.12:8080/users 发起请求.获取数据并进行处理 this.apiGet('/users', {}) .then((res) ...

  5. 完全掌握vuex

    公司项目中大量的使用了vue,感觉对vue知识的掌握也越来越熟练了,录制视频教程也让我受益匪浅,自己成长的同时,我更希望帮助其他前端小伙伴一起成长.这篇文章我们主要讲解vuex. vuex是一个专门为 ...

  6. rabbitmq-3.5.1-安裝

    系统版本:CentOS 6.5RabbitMQ-Server:3.5.1一.安装erlang1.安装准备,下载安装文件 wget https://packages.erlang-solutions.c ...

  7. Jquery常见操作多选框/复选框/checkbox

    1.判断checkbox是否为选中状态: if($("#searchNews").attr("checked")=="checked") { ...

  8. kipmi0进程单核CPU100%的解决办法

    top查看服务器进程,发现有个kipmi0的进程竟然CPU的单核占用高达100%,而且居高不下. 于是上网搜了搜大家的说法了给出的链接,大概意思是一个固件问题,可以通过修改文件来解决. 专业的解释地址 ...

  9. eas之常用源码整理

    //查看是否有相关权限 boolean hasAllotPermission=         PermissionFactory.getRemoteInstance().hasFunctionPer ...

  10. tesuto-Mobius

    求 \begin{equation*}\sum_{i=1}^n\sum_{j=1}^m[\gcd(i,j)=k]\end{equation*} 的值. 莫比乌斯反演吧. \begin{align*}& ...