結果
| 問題 | No.6 使いものにならないハッシュ |
| コンテスト | |
| ユーザー |
y_mazun
|
| 提出日時 | 2015-04-17 02:37:57 |
| 言語 | C++11 (gcc 15.3.0 + boost 1.92.0) |
| 結果 |
AC
不安定
|
| 実行時間 | 16 ms / 5,000 ms |
| + 6µs | |
| コード長 | 971 bytes |
| 記録 | |
| コンパイル時間 | 326 ms |
| コンパイル使用メモリ | 71,124 KB |
| 実行使用メモリ | 6,272 KB |
| 最終ジャッジ日時 | 2026-08-28 22:59:41 |
| 合計ジャッジ時間 | 2,425 ms |
|
ジャッジサーバーID (参考情報) |
judge3_0 / judge2_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 32 |
ソースコード
#define REP(i,n) for(int i=0; i<(int)(n); i++)
#include <queue>
#include <cstdio>
inline int getInt(){ int s; scanf("%d", &s); return s; }
#include <set>
using namespace std;
int main(){
const int k = getInt();
const int n = getInt();
vector<int> p;
vector<int> h;
for(int i = max(2, k); i <= n; i++){
bool ok = true;
for(int j = 2; j * j <= i; j++)
if(i % j == 0){ ok = false; break; }
if(!ok) continue;
p.push_back(i);
int hh = i;
while(hh >= 10){
int t = 0;
while(hh){ t += hh % 10; hh /= 10; }
hh = t;
}
h.push_back(hh);
}
int len = 0;
int ans = 0;
int fst = 0;
set<int> s;
REP(i,p.size()){
if(s.count(h[i])){
do{
s.erase(h[fst]);
}while(h[fst++] != h[i]);
}
s.insert(h[i]);
// printf("%d(%d): %d\n", p[i], h[i], p[fst]);
if(len <= i - fst + 1){
len = i - fst + 1;
ans = p[fst];
}
}
printf("%d\n", ans);
return 0;
}
y_mazun