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
Copy
3 4
output

-1


给出p,y。

求一个不大于y的,不是2,3,4,p倍数的最大的数。

仔细想一下,不是2,3,4,5,...p的倍数,也就是说是个素数!。

所以我们倒着从y开始,找第一个是素数的数字即可。

#include <cstdio>
#include <cstring>
#include <cmath>
#include <vector>
#include <iostream>
#include<set>
#include <algorithm>
using namespace std;
int p,y;
bool prime(int x)
{
    for(int i = 2; i*i<=x&&i<=p; i++) {
        if(x%i == 0)
            return false;
    }
    return true;
}
int main()
{


    cin>>p>>y;


        for(int i=y;i>p;i--)
        {
            if(prime(i))
            {
                cout<<i<<endl;
               return 0;
            }
        }
     cout<<"-1"<<endl;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值