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

题目大意:找出一个≤y的最大的不是2,3,......,p的倍数的数.

分析:想起了被noip d1t1支配的恐惧......

   没什么好的的方法,靠打表观察,可以发现答案离y非常近,从大到小枚举判断是否符合要求即可. 如何判断是否符合要求?根号复杂度枚举质因子,找到一个最小的质因子,看是否>p.  如果找到了或者是一个质数,就是答案了.

   打表找规律,发现答案所在的区间比较小就可以直接暴力了,而且cf的B题也不会很难.

#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm> using namespace std; typedef long long ll; ll p,y,anss;
bool flag = false; int main()
{
cin >> p >> y;
for (ll i = y; i >= p; i--)
{
ll ans = i;
for (ll j = ; j * j <= i; j++)
{
if (i % j == )
{
ans = j;
break;
}
}
if (ans > p)
{
flag = true;
anss = i;
break;
}
}
if (!flag)
printf("-1\n");
else
cout << anss << endl; return ;
}

Codeforces 937.B 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. B. Vile Grasshoppers

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

  4. CodeForces937B:Vile Grasshoppers(素数性质)

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

  5. A - Vile Grasshoppers

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

  6. CF937B Vile Grasshoppers

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

  7. Codeforces 937 D. Sleepy Game(DFS 判断环)

    题目链接: Sleepy Game 题意: Petya and Vasya 在玩移动旗子的游戏, 谁不能移动就输了. Vasya在订移动计划的时候睡着了, 然后Petya 就想趁着Vasya睡着的时候 ...

  8. Codeforces 937.D Sleepy Game

    D. Sleepy Game time limit per test 2 seconds memory limit per test 256 megabytes input standard inpu ...

  9. Codeforces 937.C Save Energy!

    C. Save Energy! time limit per test 1 second memory limit per test 256 megabytes input standard inpu ...

随机推荐

  1. Python学习:3.Python学习基础

    Python基础概念 一.编码 Python解释器加载.py文件中的代码的时候,对内容进行编码,在Python2.x中默认使用的是ASCII,因此我们使用Python2.x版本输出中文的时候,会出现以 ...

  2. 什么是高防服务器?如何搭建DDOS流量攻击防护系统

    关于高防服务器的使用以及需求,从以往的联众棋牌到目前发展迅猛的手机APP棋牌,越来越多的游戏行业都在使用高防服务器系统,从2018年1月到11月,国内棋牌运营公司发展到了几百家. 棋牌的玩法模式从之前 ...

  3. Leecode刷题之旅-C语言/python-88合并两个有序数组

    /* * @lc app=leetcode.cn id=88 lang=c * * [88] 合并两个有序数组 * * https://leetcode-cn.com/problems/merge-s ...

  4. Awakening Your Senses【唤醒你的感觉官能】

    Awakening Your Senses Give youself a test. Which way is the wind blowing? How many kinds of wildflow ...

  5. python2.7练习小例子(二十三)

        23):题目:求1+2!+3!+...+20!的和.     程序分析:此程序只是把累加变成了累乘. #!/usr/bin/python # -*- coding: UTF-8 -*- n = ...

  6. JAVA大作业汇总3

    JAVA大作业3 代码 ``` package thegreatwork; import java.util.; import java.io.; /Board.java 目的:里面有一些关于如何移动 ...

  7. C++11中default的使用

    In C++11, defaulted and deleted functions give you explicit control over whether the special member ...

  8. 关于 SSH Server 的整体设定

    # . 关于 SSH Server 的整体设定,包含使用的 port 啦,以及使用的密码演算方式 Port # SSH 预设使用 这个 port,您也可以使用多的 port ! # 亦即重复使用 po ...

  9. 两个完整的jquery slide多方面滑动效果实例

    实例1,需要引用jquery-ui.js <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" &qu ...

  10. dom知识总结

    一.dom节点的关系及遍历 element.firstChild; 如果节点为已知节点的第一个子节点就可以使用这个方法.此方法可以递归进行使用 element.firstChild.firstChil ...