技术好文:VileGrasshoppers

简介: 技术好文:VileGrasshoppers

"

Problem description

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 //代码效果参考:https://v.youku.com/v_show/id_XNjQwMDE4NDEzNg==.html

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

Examples

Input

3 6

3 4

Output

5

-1

Note

In the first sample case grasshopper from branch 2 reaches branches 2, 4 and 6 while branch 3 is initially settled by //代码效果参考:https://v.youku.com/v_show/id_XNjQwMDE4NDE1Mg==.html

another grasshopper. Therefore the answer is 5.

It immediately follows that there are no valid branches in second sample case.

解题思路:给两个数 p,y,求区间(p,y】中不是【2,p】之间的倍数的最大数,明显可知如果存在这个数,那么它一定是不大于y的最大素数。因为在2~1e9的范围内相邻素数之差最大不超过1e3,所以最坏的时间为1e3?sqrt(1e9)≈1e7,可以A过。

AC代码:

1 #include [/span>bits/stdc++.h

2 using namespace std;

3 int p,y;bool flag=false;

4 bool isprime(int x){

5 for(int i=2;i*i<=x&&i<=p;++i)//注意最大因子至多为p

6 if(x%i==0)return false;

7 return true;

8 }

9 int main(){

10 cinpy;

11 for(int i=y;i

12 if(isprime(i)){flag=true;cout[i[endl;break;}

13 if(!flag)cout[""-1""[endl;

14 return 0;

15 }

作者:霜雪千年

出处:

本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须在文章页面给出原文连接,否则保留追究法律责任的权利。


"
image.png
相关文章
|
9月前
|
机器学习/深度学习 存储 运维
深度学习在数据库运维中的作用与实现
深度学习在数据库运维中的作用与实现
168 14
|
安全 前端开发 API
37 Swift如何保证线程安全和同步
Swift如何保证线程安全和同步
312 0
|
11月前
|
传感器 供应链 物联网
新技术趋势与应用:区块链、物联网与虚拟现实的未来展望
【10月更文挑战第2天】 在当今快速变化的技术世界中,新兴技术如区块链、物联网和虚拟现实正在重塑我们的生活、工作和娱乐方式。这些技术不仅带来了前所未有的便利和效率,还为各行各业提供了创新的解决方案。本文将探讨这三种技术的发展趋势和应用场景,并分析它们如何共同推动社会进步。通过深入分析,我们将看到这些技术如何在未来的数字经济中扮演关键角色。
150 3
|
前端开发 Java jenkins
Jenkins+Gitlab+Nginx+SonarQube+Maven编译Java项目自动发布与基于tag版本回退
Jenkins+Gitlab+Nginx+SonarQube+Maven编译Java项目自动发布与基于tag版本回退
432 0
|
算法 Cloud Native
【刷题日记】385. 迷你语法分析器
本次刷题日记的第 33 篇,力扣题为:【刷题日记】385. 迷你语法分析器 ,中等
191 0
|
Java Maven 数据库
最详细通用mapper代码生成器配置
最详细通用mapper代码生成器配置
309 0
最详细通用mapper代码生成器配置
|
消息中间件 存储 安全
|
Java C语言 Python
Python中GIL(全局解释器锁)
Python中GIL(全局解释器锁)
166 0
|
1天前
|
人工智能 运维 安全
|
3天前
|
SpringCloudAlibaba 负载均衡 Dubbo
微服务架构下Feign和Dubbo的性能大比拼,到底鹿死谁手?
本文对比分析了SpringCloudAlibaba框架下Feign与Dubbo的服务调用性能及差异。Feign基于HTTP协议,使用简单,适合轻量级微服务架构;Dubbo采用RPC通信,性能更优,支持丰富的服务治理功能。通过实际测试,Dubbo在调用性能、负载均衡和服务发现方面表现更出色。两者各有适用场景,可根据项目需求灵活选择。
371 123
微服务架构下Feign和Dubbo的性能大比拼,到底鹿死谁手?

热门文章

最新文章