結果

問題 No.371 ぼく悪いプライムじゃないよ
ユーザー kenkooookenkoooo
提出日時 2016-05-14 04:24:05
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 24 ms / 1,000 ms
コード長 2,364 bytes
コンパイル時間 1,525 ms
コンパイル使用メモリ 168,344 KB
実行使用メモリ 4,500 KB
最終ジャッジ日時 2023-08-29 00:57:47
合計ジャッジ時間 3,588 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
4,376 KB
testcase_01 AC 3 ms
4,380 KB
testcase_02 AC 3 ms
4,380 KB
testcase_03 AC 3 ms
4,376 KB
testcase_04 AC 3 ms
4,376 KB
testcase_05 AC 3 ms
4,376 KB
testcase_06 AC 3 ms
4,380 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 3 ms
4,376 KB
testcase_10 AC 3 ms
4,376 KB
testcase_11 AC 3 ms
4,376 KB
testcase_12 AC 3 ms
4,376 KB
testcase_13 AC 2 ms
4,376 KB
testcase_14 AC 3 ms
4,376 KB
testcase_15 AC 3 ms
4,380 KB
testcase_16 AC 3 ms
4,376 KB
testcase_17 AC 2 ms
4,376 KB
testcase_18 AC 2 ms
4,376 KB
testcase_19 AC 2 ms
4,376 KB
testcase_20 AC 3 ms
4,376 KB
testcase_21 AC 2 ms
4,376 KB
testcase_22 AC 4 ms
4,376 KB
testcase_23 AC 3 ms
4,376 KB
testcase_24 AC 20 ms
4,380 KB
testcase_25 AC 24 ms
4,376 KB
testcase_26 AC 3 ms
4,376 KB
testcase_27 AC 3 ms
4,376 KB
testcase_28 AC 3 ms
4,380 KB
testcase_29 AC 16 ms
4,376 KB
testcase_30 AC 23 ms
4,376 KB
testcase_31 AC 24 ms
4,376 KB
testcase_32 AC 24 ms
4,376 KB
testcase_33 AC 23 ms
4,376 KB
testcase_34 AC 21 ms
4,376 KB
testcase_35 AC 22 ms
4,376 KB
testcase_36 AC 13 ms
4,376 KB
testcase_37 AC 23 ms
4,376 KB
testcase_38 AC 21 ms
4,380 KB
testcase_39 AC 24 ms
4,376 KB
testcase_40 AC 23 ms
4,500 KB
testcase_41 AC 21 ms
4,376 KB
testcase_42 AC 20 ms
4,380 KB
testcase_43 AC 13 ms
4,380 KB
testcase_44 AC 3 ms
4,376 KB
testcase_45 AC 3 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

/*
                   _ooOoo_
                  o8888888o
                  88" . "88
                  (| -_- |)
                  O\  =  /O
               ____/`---'\____
             .'  \\|     |//  `.
            /  \\|||  :  |||//  \
           /  _||||| -:- |||||-  \
           |   | \\\  -  /// |   |
           | \_|  ''\---/''  |   |
           \  .-\__  `-`  ___/-. /
         ___`. .'  /--.--\  `. . __
      ."" '<  `.___\_<|>_/___.'  >'"".
     | | :  `- \`.;`\ _ /`;.`/ - ` : | |
     \  \ `-.   \_ __\ /__ _/   .-` /  /
======`-.____`-.___\_____/___.-`____.-'======
                   `=---='
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
            pass System Test!
*/
#include <bits/stdc++.h>
using namespace std;

template <typename T>
std::ostream &operator<<(std::ostream &out, const std::vector<T> &v) {
  if (!v.empty()) {
    out << '[';
    std::copy(v.begin(), v.end(), std::ostream_iterator<T>(out, ", "));
    out << "\b\b]";
  }
  return out;
}
template <typename T1, typename T2>
std::ostream &operator<<(std::ostream &out, const std::pair<T1, T2> &p) {
  out << "[" << p.first << ", " << p.second << "]";
  return out;
}
template <class T, class U>
void chmin(T &t, U f) {
  if (t > f) t = f;
}
template <class T, class U>
void chmax(T &t, U f) {
  if (t < f) t = f;
}
template <typename T>
void uniq(vector<T> &v) {
  v.erase(unique(v.begin(), v.end()), v.end());
}

vector<int> primes;

void eratosthenes(int N) {
  vector<bool> is_prime(N + 1, true);
  is_prime[0] = false;
  is_prime[1] = false;
  for (int i = 2; i <= N; ++i)
    if (is_prime[i]) {
      primes.push_back(i);
      for (int j = i * 2; j <= N; j += i) {
        is_prime[j] = false;
      }
    }
}

int64_t get_min_divisor(int64_t t) {
  for (int p : primes)
    if (t % p == 0)
      return p;
    else if (p > sqrt(t + 1))
      break;
  return t;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  eratosthenes(1e5);

  int64_t L, H;
  cin >> L >> H;

  int64_t ans = -1;
  for (int i = primes.size() - 1; i >= 0; --i) {
    int64_t prime = primes[i];
    int64_t h = H / prime * prime;
    int64_t l = max(L, prime * prime);
    for (; h >= l; h -= prime) {
      int64_t divisor = get_min_divisor(h / prime);
      if (divisor < prime) {
        continue;
      }
      if (ans < 0) ans = h;
      break;
    }
  }
  cout << ans << endl;
}
0