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. Skip the Class

    BestCoder Round #92 Skip the Class  Accepts: 678  Submissions: 1285  Time Limit: 2000/1000 MS (Java/ ...

  2. Nestjs 序列化(Serialization)

    文档 在发送实际响应之前,Serializers为数据操作提供了干净的抽象层.例如,应始终从最终响应中排除敏感数据(如用户密码) λ yarn add class-transformer cats.e ...

  3. Eclipse的设置、调优、使用(解决启动卡顿等问题)----转

    eclipse调优 一般在不对eclipse进行相关设置的时候,使用eclipse总是会觉得启动好慢,用起来好卡,其实只要对eclipse的相关参数进行一些配置,就会有很大的改善. 加快启动速度 1. ...

  4. hibernate的面试总结

    hibenate的面试总结. 可能现在大家常常还会遇到一个些面试的时候问一些关于hibernate的问题,我个人觉得,这些东西一般做过开发的人在使用上没有任何的问题的,但是如果是要你来说就不一定能够说 ...

  5. p1010幂次方---(分治)

    题目描述 任何一个正整数都可以用222的幂次方表示.例如 137=27+23+20137=2^7+2^3+2^0 137=27+23+20 同时约定方次用括号来表示,即aba^bab 可表示为a(b) ...

  6. Redis的学习笔记

    一.Redis简介 1.关于关系型数据库和nosql数据库 关系型数据库是基于关系表的数据库,最终会将数据持久化到磁盘上,而nosql数据     库是基于特殊的结构,并将数据存储到内存的数据库.从性 ...

  7. 谁考了第k名

    题目描述: 在一次考试中,每个学生的成绩都不相同,现知道了每个学生的学号和成绩,求考第k名学生的学号和成绩. 输入: 第一行有两个整数,分别是学生的人数n(1≤n≤100),和求第k名学生的k(1≤k ...

  8. 项目实战02:LVS 实现负载均衡

    目录 实现基于LVS负载均衡集群的电商网站架构 实战一:LVS的NAT模式实现负载均衡 实战二:LVS的DR 模式实现负载均衡 实战三:实现80.443端口都可访问服务,且LVS实现持久连接 实验四: ...

  9. AE实现拖拽

    http://edndoc.esri.com/arcobjects/9.2/net/63391c82-c2e6-4797-b2e6-2c1d92f56f44.htm http://help.arcgi ...

  10. 线程安全 Thread Safety Problem scala concurrency 并发

    小结: 1.基于java并发模型 Scala concurrency is built on top of the Java concurrency model. 2. 将每个请求放入一个新的线程 T ...