結果
問題 | No.6 使いものにならないハッシュ |
ユーザー |
![]() |
提出日時 | 2024-03-03 00:27:25 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 6 ms / 5,000 ms |
コード長 | 1,132 bytes |
コンパイル時間 | 3,256 ms |
コンパイル使用メモリ | 257,964 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-09-29 16:31:18 |
合計ジャッジ時間 | 4,481 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 32 |
ソースコード
#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;}