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
3 6
output

5
input
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 ;
}

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

  3. A - Vile Grasshoppers

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

  4. CF937B Vile Grasshoppers

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

  5. B. Vile Grasshoppers

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

  6. Codeforces 937.B Vile Grasshoppers

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

  7. zoj 1562 反素数 附上个人对反素数性质的证明

    反素数的定义:对于不论什么正整数,其约数个数记为.比如,假设某个正整数满足:对随意的正整 数.都有,那么称为反素数. 从反素数的定义中能够看出两个性质: (1)一个反素数的全部质因子必定是从2開始的连 ...

  8. WPF中的常用布局 栈的实现 一个关于素数的神奇性质 C# defualt关键字默认值用法 接口通俗理解 C# Json序列化和反序列化 ASP.NET CORE系列【五】webapi整理以及RESTful风格化

    WPF中的常用布局   一 写在开头1.1 写在开头微软是一家伟大的公司.评价一门技术的好坏得看具体的需求,没有哪门技术是面面俱到地好,应该抛弃对微软和微软的技术的偏见. 1.2 本文内容本文主要内容 ...

  9. zoj2562:搜索+数论(反素数)

    题目大意:求n以内因子数量最多的数  n的范围为1e16 其实相当于求n以内最大的反素数... 由素数中的 算数基本原理 设d(a)为a的正因子的个数,则 d(n)=(a1+1)(a2+1)..... ...

随机推荐

  1. pl/sql小技巧

    更正方法: 然后把Automatic statistics的勾选去掉,点击apply即可

  2. 搭建Redis环境以及所遇问题(CentOS7+Redis 3.2.8)

    一.安装步骤 1. 首先需要安装gcc,把下载好的redis-3.2.8-rc2.tar.gz 放到/usr/local文件夹下 2. 进行解压 tar -zxvf redis-3.2.8-rc2.t ...

  3. LeetCode OJ--Valid Palindrome

    http://oj.leetcode.com/problems/valid-palindrome/ 判断是否为回文串 bool isPalindrome(string s) { ,j = s.leng ...

  4. 航空售票系统设计分析(Markdownpad2图片服务器上传无法显示)

    一.体系结构设计 1.系统原型图 2.体系结构环境图 3.构建结构图 二.人机交互界面设计 1.用户分析结果及建议 本次分析的主要目标关注用户评论反馈,对反馈进行归纳,设计出用户喜欢的界面样式.用户的 ...

  5. NOIP临考经验(转)

    [COGS]NOIP临考经验 1.  提前15分钟入场,此时静坐调整心态,适当的深呼吸 2.  打开编辑器并调整为自己喜欢的界面 3.  熟悉文件目录,写好准确无误的代码模板 4.  压缩包或许还不能 ...

  6. java消息队列怎么用

    消息队列的使用场景是怎样的? 经常听到诸如rebbitmq,activemq,请教一下各位前辈消息队列的使用场景是怎样的,什么时候会用到它   校验用户名等信息,如果没问题会在数据库中添加一个用户记录 ...

  7. Fragment 生命周期怎么来的?

    前言 Fragment对于 Android 开发人员来说一点都不陌生,由于差点儿不论什么一款 app 都大量使用 Fragment,所以 Fragment 的生命周期相信对于大家来说应该都非常清晰.但 ...

  8. pandas入门指南

    上一篇讲了numpy,除此之外,还有一个工具我们一定会使用,那就是pandas.如果说numpy中数据存储形式是列表的话,那么pandas中数据的存储形式更像是字典.为什么这么说呢?因为pandas中 ...

  9. atitit. hb 原生sql跨数据库解决原理 获得hb 数据库类型执行期获得Dialect

    atitit. hb 原生sql跨数据库解决原理 获得hb 数据库类型执行期获得Dialect   #-----原理 Hibernate 执行期获得Dialect   2010-07-28 12:59 ...

  10. MongoDB---出现no write has been done on this connection解决方式

    no write has been done on this connection 这个问题出现了好几天.日志里面一天出现几十次no write has been done on this conne ...