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

[分析]: 给你两个数p,y,求去掉2-y中所有2-p的数的倍数后剩下的最大值,如果没有剩下数输出-1.

[代码]:和筛法一个意思,注意最大值可以逆向枚举.只要算到sqrt(10^9)(i<=p这个条件的加入是为了防止x可能不是素数,但是x不含有2~p之间的任何一个因数)

[代码]:

#include<bits/stdc++.h>
using namespace std;
int p, y; bool ck(int n) {
for(int i = ; i * i <= n && i <= p; i++) {
if(n % i == ) {
return false;
}
}
return true;
} int main() {
cin >> p >> y;
for(int i = y; i > p; i--) {
if(ck(i)) {
printf("%d\n", i);
return ;
}
}
puts("-1");
return ;
}

筛法

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

  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. Codeforces Round #467 (div.2)

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

  3. Codeforces Round #467 Div.2题解

    A. Olympiad time limit per test 1 second memory limit per test 256 megabytes input standard input ou ...

  4. Codeforces Round #467 (Div. 1) B. Sleepy Game

    我一开始把题目看错了 我以为是博弈.. 这题就是一个简单的判环+dfs(不简单,挺烦的一题) #include <algorithm> #include <cstdio> #i ...

  5. Codeforces Round #467 (Div. 1). C - Lock Puzzle

    #include <algorithm> #include <cstdio> #include <cstring> #include <iostream> ...

  6. Codeforces Round #467 Div. 1

    B:显然即相当于能否找一条有长度为奇数的路径使得终点出度为0.如果没有环直接dp即可.有环的话可以考虑死了的spfa,由于每个点我们至多只需要让其入队两次,复杂度变成了优秀的O(kE).事实上就是拆点 ...

  7. Codeforces Round #467 (Div. 2) E -Lock Puzzle

    Lock Puzzle 题目大意:给你两个字符串一个s,一个t,长度<=2000,要求你进行小于等于6100次的shift操作,将s变成t, shift(x)表示将字符串的最后x个字符翻转后放到 ...

  8. Codeforces Round #467 (Div. 2) A. Olympiad[输入一组数,求该数列合法的子集个数]

    A. Olympiad time limit per test 1 second memory limit per test 256 megabytes input standard input ou ...

  9. C. Edgy Trees Codeforces Round #548 (Div. 2) 并查集求连通块

    C. Edgy Trees time limit per test 2 seconds memory limit per test 256 megabytes input standard input ...

随机推荐

  1. 数论:HDU1066-Last non-zero Digit in N!

    题目: Last non-zero Digit in N! Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K ...

  2. 菜鸟学Linux - 用户与用户组基础

    /etc/passwd: 用户的信息是保存在/etc/passwd下面(早期的时候,用户的密码也是放在该文件中.后来出于安全考虑,将密码放在/etc/shadow中去): /etc/group: 用户 ...

  3. 使用数组的splice方法以及循环嵌套来实现数组去重

    javascript代码如下   <script type="text/javascript"> var arr = [1,2,3,4,5,6,5,4,3,7,8,9, ...

  4. 设计模式之第0章-单例模式(Java实现)

    设计模式之第0章-单例模式(Java实现) 当当当当~首先有请最简单的单例模式登场,先来个自我介绍吧 单例模式之自我介绍 我,单例模式(Singleton Pattern)是一个比较简单的模式,我的定 ...

  5. IOS开发学习笔记043-QQ聊天界面实现

    QQ聊天界面实现 效果如下: 实现过程: 1.首先实现基本界面 头像使用 UIImageView : 文字消息使用 UIButton 标签使用 UILable :水平居中 所有元素在一个cell中,在 ...

  6. Aptana Studion出现 duplicate location重复定位报错

    1.下载SVN的时候出现报错 duplicate location 2.点击“available software sites”查看已可用的软件网站 3.在这里可以查看到SVN,勾选SVN复选框,点击 ...

  7. Mybatis使用- Mybatis JdbcType与Oracle、MySql数据类型对应列表 ; Mybatis中javaType和jdbcType对应关系

    Mybatis JdbcType与Oracle.MySql数据类型对应列表  Mybatis JdbcType Oracle MySql JdbcType ARRAY     JdbcType BIG ...

  8. python中 in, any 和 all用法

    in if x == 1 or y == 1 or z == 1: print('passed') if 1 in (x, y, z): print('passed') any if x or y o ...

  9. jquery的html、text、val的用法

    .html()用为读取和修改元素的HTML标签 .text()用来读取或修改元素的纯文本内容 .val()用来读取或修改表单元素的value值. 这三个方法功能上的对比 .html(),.text() ...

  10. setTimeOut传参数

    最近,因项目需要,需要实现setTimeOut传参数的功能,搜索了很多的资源.终于找到一个比较好的方法了,记录下来,与大家分享. 无论是window.setTimeOut还是window.setInt ...