Codeforces Round #467 (Div. 2) B. Vile Grasshoppers[求去掉2-y中所有2-p的数的倍数后剩下的最大值]
1 second
256 megabytes
standard input
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.
The only line contains two integers p and y (2 ≤ p ≤ y ≤ 109).
Output the number of the highest suitable branch. If there are none, print -1 instead.
3 6
5
3 4
-1
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.
[分析]: 给你两个数p,y,求去掉2-y中所有2-p的数的倍数后剩下的最大值,如果没有剩下数输出-1.
[代码]:和筛法一个意思,注意最大值可以逆向枚举.只要算到sqrt(10^9)(i<=p这个条件的加入是为了防止x可能不是素数,但是x不含有2~p之间的任何一个因数)
[代码]:
#include<bits/stdc++.h>
using namespace std;
int p, y; bool ck(int n) {
for(int i = ; i * i <= n && i <= p; i++) {
if(n % i == ) {
return false;
}
}
return true;
} int main() {
cin >> p >> y;
for(int i = y; i > p; i--) {
if(ck(i)) {
printf("%d\n", i);
return ;
}
}
puts("-1");
return ;
}
筛法
Codeforces Round #467 (Div. 2) B. Vile Grasshoppers[求去掉2-y中所有2-p的数的倍数后剩下的最大值]的更多相关文章
- 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 ...
- Codeforces Round #467 (div.2)
Codeforces Round #467 (div.2) 我才不会打这种比赛呢 (其实本来打算打的) 谁叫它推迟到了\(00:05\) 我爱睡觉 题解 A. Olympiad 翻译 给你若干人的成绩 ...
- Codeforces Round #467 Div.2题解
A. Olympiad time limit per test 1 second memory limit per test 256 megabytes input standard input ou ...
- Codeforces Round #467 (Div. 1) B. Sleepy Game
我一开始把题目看错了 我以为是博弈.. 这题就是一个简单的判环+dfs(不简单,挺烦的一题) #include <algorithm> #include <cstdio> #i ...
- Codeforces Round #467 (Div. 1). C - Lock Puzzle
#include <algorithm> #include <cstdio> #include <cstring> #include <iostream> ...
- Codeforces Round #467 Div. 1
B:显然即相当于能否找一条有长度为奇数的路径使得终点出度为0.如果没有环直接dp即可.有环的话可以考虑死了的spfa,由于每个点我们至多只需要让其入队两次,复杂度变成了优秀的O(kE).事实上就是拆点 ...
- Codeforces Round #467 (Div. 2) E -Lock Puzzle
Lock Puzzle 题目大意:给你两个字符串一个s,一个t,长度<=2000,要求你进行小于等于6100次的shift操作,将s变成t, shift(x)表示将字符串的最后x个字符翻转后放到 ...
- 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 ...
- C. Edgy Trees Codeforces Round #548 (Div. 2) 并查集求连通块
C. Edgy Trees time limit per test 2 seconds memory limit per test 256 megabytes input standard input ...
随机推荐
- 动态规划:HDU1224-Free DIY Tour
Free DIY Tour Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
- MySQL基础9-主键约束、外键约束、等值连接查询、一对一和多对多关系
1.主键约束和外键约束 外键约束 * 外键必须是另一表的主键的值(外键要引用主键!) * 外键可以重复 * 外键可以为空 * 一张表中可以有多个外键! 概念模型在数据库中成为表 数据库表中的多对一关系 ...
- MySQL基础2-创建表和主键约束
1.创建表 在操作数据表之前,应该使用"USE 数据库名"指定操作是在哪个数据库中进行 主键约束(唯一标识) ****非空*** ****唯一*** ****被引用****(学习外 ...
- VMware workstation 9.0中安装Windows server 2012 和 Hyper-v
一.准备工作 首先下载和安装和安装VMware workstation 9.0 下载Windows server 2012 iso镜像文件 二.安装Windows server 2012虚拟机 1.新 ...
- 34、Java集合框架List,Map,Set等全面介绍(转载)
Java Collections Framework是Java提供的对集合进行定义,操作,和管理的包含一组接口,类的体系结构. Java集合框架的基本接口/类层次结构: java.util.C ...
- 【Unique Paths】cpp
题目: A robot is located at the top-left corner of a m x n grid (marked 'Start' in the diagram below). ...
- IOS开发学习笔记022-imageView实现动画
这里要播放的动画是很多张连续的动画,连续播放就会显示出动画效果. 大概过程是: 新建一个single view application ,然后添加一个image View控件到视图.给image vi ...
- 《HTTP协议详解》读书笔记---请求篇之消息报头
不管是请求消息还是响应消息都包含消息报头,那么消息报头包含哪些内容?他们都代表什么含义呢?以下将带着 这些问题去学习消息报头. http消息(不管是请求消息还是响应消息)都是由开始行,消息报头(可选) ...
- python re 模块小结
前言: 本人环境windows 7 64位,python2.7 re是什么: regular expression缩写,意为正则表达式,是python的众多模块之一 re用途: 从文本中有选择的批量抽 ...
- hdu6134[莫比乌斯反演] 2017多校8
/*hdu6134[莫比乌斯反演] 2017多校8*/ #include <bits/stdc++.h> using namespace std; typedef long long LL ...