結果
問題 |
No.6 使いものにならないハッシュ
|
ユーザー |
![]() |
提出日時 | 2015-10-28 11:35:03 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 39 ms / 5,000 ms |
コード長 | 789 bytes |
コンパイル時間 | 1,626 ms |
コンパイル使用メモリ | 162,168 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-09-16 16:30:13 |
合計ジャッジ時間 | 2,655 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 32 |
ソースコード
#include <bits/stdc++.h> using namespace std; int n, m; int cnt[10]; bool isprime(int x) { if (x <= 1) return false; for (int i = 2; i * i <= x; i++){ if (x % i == 0) return false; } return true; } int hash_(int x) { stringstream ss; ss << x; string s; ss >> s; if (s.size() == 1) return s[0] - '0'; int sum = 0; for (char c : s) sum += c - '0'; return hash_(sum); } int main() { cin >> n >> m; vector<int> ps; vector<int> hs; for (int i = n; i <= m; i++){ if (isprime(i)){ ps.push_back(i); hs.push_back(hash_(i)); } } int l = 0, r = 0; int len = 0, res = 0; while (r < ps.size()){ cnt[hs[r]]++; while (cnt[hs[r]] == 2){ cnt[hs[l++]]--; } if (len <= r - l + 1){ res = ps[l]; len = r - l + 1; } r++; } cout << res << endl; }