結果
問題 | No.6 使いものにならないハッシュ |
ユーザー |
![]() |
提出日時 | 2015-02-15 18:59:13 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 4 ms / 5,000 ms |
コード長 | 1,044 bytes |
コンパイル時間 | 541 ms |
コンパイル使用メモリ | 62,360 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-09-16 16:23:54 |
合計ジャッジ時間 | 1,550 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 32 |
ソースコード
#include <iostream> #include <algorithm> #include <sstream> #include <vector> #include <cstring> using namespace std; static int get_hash(int n) { if (n < 10) { return n; } int sum = 0; while (n > 0) { sum += n % 10; n /= 10; } return get_hash(sum); } int main(int argc, char *argv[]) { string s; getline(cin, s); int K = atoi(s.c_str()); getline(cin, s); int N = atoi(s.c_str()); static int f[200001] = {}; static int p[200001] = {}; static int h[200001] = {}; int primes = 0; int pos[10] = {}; int mx[11] = {}; int count = 0; int max_count = 0; int ans = 0; for (int i = 2; i <= N; ++i) { if (!f[i]) { for (int j = i * 2; j <= N; j += i) { f[j] = 1; } if (i >= K) { ++count; int hash = get_hash(i); p[primes] = i; h[primes] = hash; ++primes; int c = primes - mx[hash]; if (c < count) { count = c; } if (count >= max_count) { max_count = count; ans = p[primes - count]; } mx[hash] = primes; } } } cout << ans << endl; return 0; }