結果

問題 No.371 ぼく悪いプライムじゃないよ
ユーザー kenjiiiHkenjiiiH
提出日時 2016-05-14 17:39:05
言語 C++11
(gcc 11.4.0)
結果
TLE  
実行時間 -
コード長 959 bytes
コンパイル時間 620 ms
コンパイル使用メモリ 71,044 KB
実行使用メモリ 13,752 KB
最終ジャッジ日時 2024-04-15 21:31:18
合計ジャッジ時間 3,681 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
using namespace std;

vector<long long> getPrimes(int n) {
  vector<bool> ok(n, true);
  ok[0] = ok[1]= false;
  vector<long long> ret;
  for (int i = 2; i < n; i++) {
    if (!ok[i])
      continue;
    ret.push_back(i);
    for (int j = i; j < n; j += i)
      ok[j] = false;
  }
  return ret;
}

long long fac(long long x) {
  for (long long d = 2; d * d <= x; d++) {
    if (x % d == 0)
      return d;
  }
  return x;
}

int main(int argc, char *argv[])
{
  long long l, h;
  cin >> l >> h;

  pair<long long, long long> ret = make_pair(0, 0);
  vector<long long> ps = getPrimes(1e6);
  for (int i = ps.size()-1; i >= 0; i--) {
    if (ps[i] < ret.first) break;
    long long x = h / ps[i] * ps[i];
    while (l <= x) {
      long long d = min(ps[i], fac(x/ps[i]));
      ret = max(ret, make_pair(d, x));
      x -= ps[i];
    }
  }
  cout << ret.second << endl;
  
  return 0;
}
0