zoukankan      html  css  js  c++  java
  • B. Vile Grasshoppers

    http://codeforces.com/problemset/problem/937/B

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

     水题

    // 去吧!皮卡丘! 把AC带回来!
    //      へ     /|
    //   /\7    ∠_/
    //   / │   / /
    //  │ Z _,< /   /`ヽ
    //  │     ヽ   /  〉
    //  Y     `  /  /
    //  イ● 、 ●  ⊂⊃〈  /
    //  ()  へ    | \〈
    //   >ー 、_  ィ  │ //
    //   / へ   / ノ<| \\
    //   ヽ_ノ  (_/  │//
    //    7       |/
    //    >―r ̄ ̄`ー―_
    //**************************************
    #pragma comment(linker, "/STACK:1024000000,1024000000")
    #include <bits/stdc++.h>
    using namespace std;
    typedef long long ll;
    #define inf 2147483647
    const ll INF = 0x3f3f3f3f3f3f3f3fll;
    #define ri register int
    template <class T> inline T min(T a, T b, T c) { return min(min(a, b), c); }
    template <class T> inline T max(T a, T b, T c) { return max(max(a, b), c); }
    template <class T> inline T min(T a, T b, T c, T d) {
      return min(min(a, b), min(c, d));
    }
    template <class T> inline T max(T a, T b, T c, T d) {
      return max(max(a, b), max(c, d));
    }
    #define scanf1(x) scanf("%d", &x)
    #define scanf2(x, y) scanf("%d%d", &x, &y)
    #define scanf3(x, y, z) scanf("%d%d%d", &x, &y, &z)
    #define scanf4(x, y, z, X) scanf("%d%d%d%d", &x, &y, &z, &X)
    #define pi acos(-1)
    #define me(x, y) memset(x, y, sizeof(x));
    #define For(i, a, b) for (ll i = a; i <= b; i++)
    #define FFor(i, a, b) for (ll i = a; i >= b; i--)
    #define bug printf("***********
    ");
    #define mp make_pair
    #define pb push_back
    const int maxn = 3e5 + 10;
    const int maxx = 1e6 + 10;
    // name*******************************
    ll p, y;
    // function******************************
    
    //***************************************
    int main() {
      cin >> p >> y;
      bool flag = true;
      FFor(i, y, p + 1) {
        flag = true;
        for (ll j = 2; j <= p && j * j <= i; j++) {
          if (i % j == 0) {
            flag = false;
            break;
          }
        }
        if (flag) {
          cout << i;
          return 0;
        }
      }
      cout<<-1;
    
      return 0;
    }
    View Code
  • 相关阅读:
    android基础开发之scrollview
    java网络---再论URL & URI
    Android Studio 有用的插件
    java网络---查找Internet
    java网络---流
    Qt学习之路(1)------Qt常用类用法说明
    将批量下载的博客导入到手机后,通过豆约翰博客阅读器APP(Android手机)进行浏览,白字黑底,保护眼睛,图文并茂。
    如何收藏互联网上的任意网页到系统某个分类下,之后进行批量导出发布等---博客备份专家的博文收藏功能您不可不知
    很喜欢看某方面的文章,如何将不同站点,不同博主同一类别的文章归类整合到一起,再批量导出成各种格式---豆约翰博客备份专家新增按分类收藏博文功能
    豆约翰博客备份专家博客导出示例(PDF,CHM)
  • 原文地址:https://www.cnblogs.com/planche/p/8613298.html
Copyright © 2011-2022 走看看