結果
問題 | No.6 使いものにならないハッシュ |
ユーザー |
![]() |
提出日時 | 2014-11-25 20:01:32 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 5 ms / 5,000 ms |
コード長 | 1,205 bytes |
コンパイル時間 | 2,076 ms |
コンパイル使用メモリ | 162,284 KB |
実行使用メモリ | 5,888 KB |
最終ジャッジ日時 | 2024-09-16 16:22:47 |
合計ジャッジ時間 | 3,170 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 32 |
ソースコード
#include <bits/stdc++.h> using namespace std; #define rep(i,n) repi(i,0,n) #define repi(i,a,b) for(int i=int(a);i<int(b);++i) #define long int64_t #define ulong uint64_t const int N = 200000; int not_prime[N + 1] = {1, 1}; int h[N + 1], p[N + 1], tmp[47]; void prepare() { for (int i = 2; i * i <= N; ++i) { if (not_prime[i]) continue; for (int j = i * i; j <= N; j += i) { not_prime[j] = 1; } } rep(i, 10) h[i] = i; repi(i, 10, N + 1) { h[i] = h[h[i / 10] + i % 10]; } repi(i, 1, N + 1) { if (not_prime[i]) continue; p[i] = tmp[h[i]]; tmp[h[i]] = i; } } int k, n; void input() { cin >> k >> n; } void solve() { int mx = 0, ans = -1; queue<int> q; repi(i, k, n + 1) { if (not_prime[i]) continue; while (not q.empty() and q.front() <= p[i]) q.pop(); q.push(i); if ((int) q.size() >= mx) { mx = (int) q.size(), ans = q.front(); } } cout << ans << endl; } int main() { cin.tie(0); ios_base::sync_with_stdio(false); prepare(); input(); solve(); }