結果
| 問題 |
No.6 使いものにならないハッシュ
|
| ユーザー |
|
| 提出日時 | 2015-02-21 21:20:59 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 3 ms / 5,000 ms |
| コード長 | 953 bytes |
| コンパイル時間 | 761 ms |
| コンパイル使用メモリ | 64,136 KB |
| 実行使用メモリ | 5,376 KB |
| 最終ジャッジ日時 | 2024-09-16 16:24:16 |
| 合計ジャッジ時間 | 1,663 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 32 |
ソースコード
#include <iostream>
#include <cstring>
#include <vector>
#include <algorithm>
typedef std::pair<int, int> P;
const int max = 200001;
bool isPrime[max];
std::vector<P> v;
void init(){
memset(isPrime, -1, sizeof(isPrime));
isPrime[0] = false;
isPrime[1] = false;
for (int i = 2; i*i <= max; i++){
if (!isPrime[i])continue;
for (int j = i * 2; j < max; j += i)isPrime[j] = false;
}
for (int i = 2; i < max; i++){
if (isPrime[i])v.push_back(P(i, i % 9));
}
}
int main(){
init();
int n, k;
std::cin >> n >> k;
int s = 0, e = v.size() - 1;
while (v[s].first < n)s++;
while (v[e].first > k)e--;
int ans = 0, max_size = 0;
for (int i = e; i >= s; i--){
int cnt[9], size = 0;
memset(cnt, 0, sizeof(cnt));
int j = 0;
while (cnt[v[i + j].second] == 0 && i + j <= e){
cnt[v[i + j].second]++;
size++;
j++;
}
if (size > max_size)ans = v[i].first, max_size = size;
}
std::cout << ans << std::endl;
return 0;
}