結果

問題 No.6 使いものにならないハッシュ
ユーザー a01sa01toa01sa01to
提出日時 2024-03-03 00:27:25
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 6 ms / 5,000 ms
コード長 1,132 bytes
コンパイル時間 3,161 ms
コンパイル使用メモリ 257,620 KB
実行使用メモリ 6,676 KB
最終ジャッジ日時 2024-03-03 00:27:29
合計ジャッジ時間 4,670 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,676 KB
testcase_01 AC 1 ms
6,676 KB
testcase_02 AC 6 ms
6,676 KB
testcase_03 AC 3 ms
6,676 KB
testcase_04 AC 3 ms
6,676 KB
testcase_05 AC 3 ms
6,676 KB
testcase_06 AC 4 ms
6,676 KB
testcase_07 AC 3 ms
6,676 KB
testcase_08 AC 3 ms
6,676 KB
testcase_09 AC 3 ms
6,676 KB
testcase_10 AC 2 ms
6,676 KB
testcase_11 AC 2 ms
6,676 KB
testcase_12 AC 5 ms
6,676 KB
testcase_13 AC 3 ms
6,676 KB
testcase_14 AC 3 ms
6,676 KB
testcase_15 AC 4 ms
6,676 KB
testcase_16 AC 3 ms
6,676 KB
testcase_17 AC 4 ms
6,676 KB
testcase_18 AC 6 ms
6,676 KB
testcase_19 AC 5 ms
6,676 KB
testcase_20 AC 5 ms
6,676 KB
testcase_21 AC 2 ms
6,676 KB
testcase_22 AC 5 ms
6,676 KB
testcase_23 AC 5 ms
6,676 KB
testcase_24 AC 4 ms
6,676 KB
testcase_25 AC 4 ms
6,676 KB
testcase_26 AC 5 ms
6,676 KB
testcase_27 AC 4 ms
6,676 KB
testcase_28 AC 3 ms
6,676 KB
testcase_29 AC 5 ms
6,676 KB
testcase_30 AC 5 ms
6,676 KB
testcase_31 AC 5 ms
6,676 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
  #include "settings/debug.cpp"
  #define _GLIBCXX_DEBUG
#else
  #define Debug(...) void(0)
#endif
#define rep(i, n) for (int i = 0; i < (n); ++i)
using ll = long long;
using ull = unsigned long long;

inline int hashfn(int x) {
  while (x >= 10) {
    string s = to_string(x);
    int sum = 0;
    for (char c : s) sum += c - '0';
    x = sum;
  }
  return x;
}

int main() {
  int k, n;
  cin >> k >> n;
  vector<bool> isPrime(n + 1, true);
  isPrime[0] = isPrime[1] = false;
  for (ll i = 2; i <= n; i++) {
    if (isPrime[i]) {
      for (ll j = i * i; j <= n; j += i) {
        isPrime[j] = false;
      }
    }
  }
  vector<pair<int, int>> p;
  for (int i = k; i <= n; i++) {
    if (isPrime[i]) p.push_back({ i, hashfn(i) });
  }
  pair<int, int> ans = { 0, 0 };
  set<int> st;
  int l = 0, r = 0;
  while (r < p.size()) {
    while (r < p.size() && !st.contains(p[r].second)) {
      st.insert(p[r].second);
      r++;
    }
    if (r - l >= ans.first) ans = { r - l, p[l].first };
    st.erase(p[l].second);
    l++;
  }
  cout << ans.second << endl;
  return 0;
}
0