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

给你两个数n,m,求去掉2-m中所有2-n的数的倍数后剩下的最大值,如果没有剩下数输出-1.

素数的变形

#include<map>
#include<set>
#include<cmath>
#include<queue>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
#define maxn 10000010
#define debug(a) cout << #a << " " << a << endl
using namespace std;
typedef long long ll;
int main() {
int n,m;
while( cin >> n >> m ) {
int flag = ;
for( int i = m; i >= n; i -- ) { //2-n在2-m中肯定有直接去掉
int ans = ;
for( int j = ; j <= && j <= n; j ++ ) {//注意这里只要算到sqrt(10^9)
if( i % j == ) {
ans ++;
}
}
if( ans == ) {
flag = ;
cout << i << endl;
break;
}
}
if( !flag ) {
cout << "-1" << endl;
}
}
return ;
}

CF937B 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. A - Vile Grasshoppers

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

  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. AI and Robot

    Have you ever seen a movie called "Ex Machina"?  I like this movie very much. Artificial i ...

  2. 配置VNC并远程控制服务器(电脑)

    先象征性介绍一下: VNC (Virtual Network Console)是虚拟网络控制台的缩写, 它是一款基于 UNIX 和 Linux 操作系统的优秀.免费.开源的远程控制工具软件. 然后开始 ...

  3. FutrueTask原理及源码分析

    1.前言 相信很多人了解到FutureTask是因为ThreadPoolExecutor.submit方法,根据ThreadPoolExecutor.submit的使用,我们可以先猜一下FutureT ...

  4. 8.9 day30 并发编程 进程理论 进程方法 守护进程 互斥锁

    多道技术 1.空间上的复用 多个程序共用一套计算机硬件 多道技术原理 2.时间上的复用 ​ 切换+保存状态 ​ 1.当一个程序遇到IO操作 操作系统会剥夺该程序的CPU执行权限( 提高了CPU的利用率 ...

  5. Linux之vim详解

    第一次使用vim,啥都不懂,输入也不能输入,退出也不会退出,特别的尴尬....后来慢慢的接触学习,发现vim真的挺好用的,不过上手有点慢,多用就对了,用多了我相信你也会喜欢这个文本编辑工具的 一.vi ...

  6. Go调度器介绍和容易忽视的问题

    本文记录了本人对Golang调度器的理解和跟踪调度器的方法,特别是一个容易忽略的goroutine执行顺序问题,看了很多篇Golang调度器的文章都没提到这个点,分享出来一起学习,欢迎交流指正. 什么 ...

  7. Java - 手动解析不带引号的JSON字符串

    目录 1 需求说明 2 解析代码 2.1 实现思路 2.2 详细代码 2.3 测试样例 1 需求说明 项目中遇到了一批不带引号的类JSON格式的字符串: {Name:Heal,Age:20,Tag:[ ...

  8. HelloDjango 第 09 篇:让博客支持 Markdown 语法和代码高亮

    作者:HelloGitHub-追梦人物 文中涉及的示例代码,已同步更新到 HelloGitHub-Team 仓库 为了让博客文章具有良好的排版,显示更加丰富的格式,我们使用 Markdown 语法来书 ...

  9. 详解python函数的参数

    详解python函数的参数 一.参数的定义 1.函数的参数在哪里定义 在python中定义函数的时候,函数名后面的括号里就是用来定义参数的,如果有多个参数的话,那么参数之间直接用逗号, 隔开 案列: ...

  10. springCould:使用Feign 实现声明式服务调用

    一.Spring Cloud Feign概念引入通过前面的随笔,我们了解如何通过Spring Cloud ribbon进行负责均衡,如何通过Spring Cloud Hystrix进行服务断路保护,两 ...