Codeforces 937.B Vile Grasshoppers
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.
题目大意:找出一个≤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的更多相关文章
- 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) B. Vile Grasshoppers[求去掉2-y中所有2-p的数的倍数后剩下的最大值]
B. Vile Grasshoppers time limit per test 1 second memory limit per test 256 megabytes input standard ...
- B. Vile Grasshoppers
http://codeforces.com/problemset/problem/937/B The weather is fine today and hence it's high time to ...
- CodeForces937B:Vile Grasshoppers(素数性质)
The weather is fine today and hence it's high time to climb the nearby pine and enjoy the landscape. ...
- A - Vile Grasshoppers
Problem description The weather is fine today and hence it's high time to climb the nearby pine and ...
- CF937B Vile Grasshoppers
Vile Grasshoppers time limit per test 1 second memory limit per test 256 megabytes input standard in ...
- Codeforces 937 D. Sleepy Game(DFS 判断环)
题目链接: Sleepy Game 题意: Petya and Vasya 在玩移动旗子的游戏, 谁不能移动就输了. Vasya在订移动计划的时候睡着了, 然后Petya 就想趁着Vasya睡着的时候 ...
- Codeforces 937.D Sleepy Game
D. Sleepy Game time limit per test 2 seconds memory limit per test 256 megabytes input standard inpu ...
- Codeforces 937.C Save Energy!
C. Save Energy! time limit per test 1 second memory limit per test 256 megabytes input standard inpu ...
随机推荐
- Blah数集
Blah数集 描述 大数学家高斯小时候偶然间发现一种有趣的自然数集合Blah,对于以a为基的集合Ba定义如下: (1) a是集合Ba的基,且a是Ba的第一个元素: (2)如果x在集合Ba中,则2x+1 ...
- codevs 1214 线段覆盖/1643 线段覆盖 3
1214 线段覆盖/1214 线段覆盖 时间限制: 1 s 空间限制: 128000 KB 题目等级 : 黄金 Gold 题目描述 Description 给定x轴上的N(0< ...
- OrCAD生成网表
1. 先选中.dsn设计文件 2. 按照默认设置,点击OK即可生成网表
- 多表头的DataGridView
上次在程序中要用到多表头的DataGridView,在网上搜索了一个,感觉还不错,现在简单的介绍一下它的用法.首先得把这个dll拷贝到相应的目录下,dll名称是myMultiColHea ...
- ubuntu 14.04安装nginx+php
转自:http://www.cnblogs.com/helinfeng/p/4219051.html 基于最新的Ubuntu 14.04(2014年9月)搭建nginx.php.mysql环境,以下全 ...
- Qt Qwdget 汽车仪表知识点拆解4 另类进度条实现
先贴上效果图,注意,没有写逻辑,都是乱动的 注意看一下,右面的这两个进度条,有瑕疵,就是我没有把图片处理干净,这里犹豫我不知道这个具体的弧度,也没法绘制,就偷懒了 现在上面放一个UI,把两个进度条抠空 ...
- selenium自动化登录qq网页
一个简单的登录网页上qq的脚本,通过此脚本了解到有些位置是无法通过xpath来定位的反倒是By定位更方便 #encoding=utf-8 from selenium import webdriver ...
- jmeter接口测试--获取token
Jmeter进行接口测试-提取token 项目一般都需要进行登陆才能进行后续的操作,登陆有时发送的请求会带有token,因此, 需要使用后置处理器中的正则表达式提取token,然后用BeanShell ...
- CodeForces - 948C(前缀和 + 二分)
链接:CodeForces - 948C 题意:N天,每天生产一堆雪体积 V[i] ,每天每堆雪融化 T[i],问每天融化了多少雪. 题解:对 T 求前缀和,求每一堆雪能熬过多少天,再记录一下多余的就 ...
- 牛客网暑期ACM多校训练营(第七场):J-Sudoku Subrectangles
链接:J-Sudoku Subrectangles 题意:给出 n * m 的字母矩阵,公52种字母.求出不含重复元素的子矩阵的个数. 题解: L[i][j]:s[i][j] ~ s[i][ j - ...