結果

問題 No.371 ぼく悪いプライムじゃないよ
ユーザー kenkooookenkoooo
提出日時 2016-05-14 00:29:13
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 2,841 bytes
コンパイル時間 1,493 ms
コンパイル使用メモリ 164,260 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-04-15 18:01:12
合計ジャッジ時間 3,830 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

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> eratosthenes(int N) {
  vector<bool> is_prime(N + 1, true);
  vector<int> primes;
  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;
      }
    }
  return primes;
}

int64_t L, H;
vector<int> primes;
int N;

int64_t dfs_check(int64_t d, int pos) {
  int64_t ans = -1;
  if (L <= d && d <= H) ans = d;
  for (int i = pos; i < N; ++i) {
    if (d * primes[i] > H) break;
    chmax(ans, dfs_check(d * primes[i], i));
  }
  return ans;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  primes = eratosthenes(1e5);
  N = primes.size();
  cin >> L >> H;

  int64_t ans = 0;
  for (int i = N - 1; i >= 100; --i) {
    int64_t d = dfs_check(primes[i], i);
    if (d > primes[i]) {
      ans = d;
      break;
    }
  }
  if (ans == 0) {
    for (int i = 100; i >= 0; --i) {
      int prime = primes[i];

      int64_t h;
      for (h = H; h >= L; h--)
        if (h % prime == 0) break;
      if (h % prime != 0) continue;

      for (; h >= L; h -= prime) {
        bool ok = true;
        for (int j = i - 1; j >= 0; --j) {
          if (h % primes[j] != 0) continue;
          ok = false;
          break;
        }
        if (ok) {
          ans = h;
          break;
        }
      }
      if (ans > 0) break;
    }
  }

  assert(ans > 0);
  cout << ans << endl;
}
0