zoukankan      html  css  js  c++  java
  • CF937B Vile Grasshoppers

    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 2to 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
    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.

     给你两个数n,m,求去掉2-m中所有2-n的数的倍数后剩下的最大值,如果没有剩下数输出-1.

    素数的变形

    #include<map>
    #include<set>
    #include<cmath>
    #include<queue>
    #include<cstdio>
    #include<cstdlib>
    #include<cstring>
    #include<iostream>
    #include<algorithm>
    #define maxn 10000010
    #define debug(a) cout << #a << " " << a << endl
    using namespace std;
    typedef long long ll;
    int main() {
        int n,m;
        while( cin >> n >> m ) {
            int flag = 0;
            for( int i = m; i >= n; i -- ) { //2-n在2-m中肯定有直接去掉
                int ans = 0;
                for( int j = 2; j <= 100000 && j <= n; j ++ ) {//注意这里只要算到sqrt(10^9)
                    if( i % j == 0 ) {
                        ans ++;
                    }
                }
                if( ans == 0 ) {
                    flag = 1;
                    cout << i << endl;
                    break;
                }
            }
            if( !flag ) {
                cout << "-1" << endl;
            }
        }
        return 0;
    }
    彼时当年少,莫负好时光。
  • 相关阅读:
    [导入]如何使用C#调用非托管DLL函数
    [导入]ASP.NET 2.0 Page的执行顺序
    [导入]C#实现捕获当前屏幕截图(转)
    初学者入门经典:Java环境配置大全
    [导入]使用母版页时内容页如何使用css和javascript(转)
    CruiseControl.NET配置总结
    使用SQL语句清空数据库所有表的数据
    运行时修改config文件
    [导入]Repater 控件的应用(学习)
    [导入]PictureBox 读取图片及绘画
  • 原文地址:https://www.cnblogs.com/l609929321/p/8473046.html
Copyright © 2011-2022 走看看