2018-03-03

http://codeforces.com/problemset/problem/937/B

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

题意:你在1的位置,从2到p都是蚱蜢们的位置,每个蚱蜢的跳法:对于位置x的蚱蜢,可以跳到2*x,3*x...不超过y。问你找一个不超过y的最大位置,让所有蚱蜢都跳不到。

想法:判断素数的变形,暴力肯定TLE。

Code

 #include<string.h>
#include<cmath>
#include<cstdio>
#include<algorithm>
#include<iostream>
#include<vector>
#include<queue>
using namespace std;
#define MAX 0x3f3f3f3f
#define fi first
#define se second
#define LL long long
int main()
{
LL p,y,ans;
cin>>p>>y;
int cflag=;
for(int i=y;i>p;i--)
{
int flag=;
for(int j=;j*j<=i&&j<=p;j++) //j<=p
{
if(i%j==)
{
flag=;
break;
}
}
if(flag==)
{
//本来还企图在这里搞一个循环去遍历最大的素数之后的数,好傻...
ans=i;
cflag=;
break;
}
}
if(cflag) cout<<ans;
else cout<<-;
}

Codeforces Round #467 (Div. 2) B. Vile Grasshoppers的更多相关文章

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

  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. Codeforces Round #366 (Div. 2) ABC

    Codeforces Round #366 (Div. 2) A I hate that I love that I hate it水题 #I hate that I love that I hate ...

随机推荐

  1. Linux 的基本操作(系统的安装)

    操作系统的安装: 操作系统的安装 这次安装系统也是基于CentOS的安装.把光盘插入光驱,设置bios光驱启动.进入光盘的欢迎界面. 其中有两个选项,可以直接按回车,也可以在当前界面下输入 linux ...

  2. dedecms (织梦)漏洞&exp整理

    [通杀]dedecms plussearch.php 注入漏洞利用方式看结果如果提示Safe Alert: Request Error step 2 !那么直接用下面的exp查看源代码打印帮助1 /p ...

  3. 1 主机WiFi连接下与虚拟机通信问题

    环境: 主机:win10系统 虚拟机软件:VMware 虚拟机:winserver 2012 R2 datacenter (数据中心版) 网络上有很多方法说设置NAT模式,并不好用,主机如果用网线连接 ...

  4. SQL 资源整理

    https://linux.linuxidc.com/index.php 资源链接:linux.linuxidc.com SQL必知必会(第4版)是SQL经典畅销书,内容丰富,简洁实用.本书是麻省理工 ...

  5. Oracle对于敏感数据的处理,可以采用策略(dbms_rls.add_policy)

    Oracle Policy的简单说明: Policy应用于数据行访问权限控制时,其作用简而言之,就是在查询数据表时,自动在查询结果上加上一个Where子句.假如该查询已有where子句,则在该Wher ...

  6. EasyUI实现分页、搜索、行按钮功能

    1.html+js代码: <html> <head> <meta name="viewport" content="width=device ...

  7. git 不能创建分支

    git 不能创建分支,如下 fatal: cannot lock ref 'refs/heads/hotfix/aa': 'refs/heads/hotfix' exists; cannot crea ...

  8. array 和 alloc init 以及 new 区别

    当你使用new.alloc或copy方法创建一个对象时,该对象的引用计数器值为1.当不再使用该对象时,你要负责向该对象发送一条release或autorelease消息.这样,该对象将在其使用寿命结束 ...

  9. SharePoint开启错误提示

    1,打开80下面的Web.config文件2,CallStack="true" 和 <customErrors mode="Off" /> < ...

  10. SVN修改已经提交过记录的日志和作者

    原 SVN修改已经提交过记录的日志和作者 使用TortoiseSVN管理代码,对于已经提交的记录,可以修改提交作者和提交日志,不过会报如下错误: Repository has not been ena ...