結果
| 問題 |
No.6 使いものにならないハッシュ
|
| コンテスト | |
| ユーザー |
hogeover30
|
| 提出日時 | 2015-02-12 20:12:39 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 5 ms / 5,000 ms |
| コード長 | 961 bytes |
| コンパイル時間 | 751 ms |
| コンパイル使用メモリ | 61,308 KB |
| 実行使用メモリ | 5,376 KB |
| 最終ジャッジ日時 | 2024-09-16 16:23:39 |
| 合計ジャッジ時間 | 1,666 ms |
|
ジャッジサーバーID (参考情報) |
judge6 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 32 |
ソースコード
#include <iostream>
#include <algorithm>
using namespace std;
const int N=200001;
int c[N], memo[N], p[N];
int func(int n)
{
if (n<10) return n;
int& res=memo[n];
if (res) return res;
int t=0;
while (n) { t+=n%10; n/=10; }
return res=func(t);
}
int main()
{
c[0]=c[1]=1;
for(int i=2;i*i<N;++i) if (!c[i])
for(int j=i*i;j<N;j+=i) c[j]=1;
int n, k;
while (cin>>k>>n) {
int m=0, res=0, maxlen=0, s=0, e=0, a[10]={};
for(int i=k;i<=n;++i) if (!c[i]) {
p[m++]=i;
e=m-1;
if (++a[func(i)]>1) {
fill(a, a+10, 0);
for(int j=0;j<10;++j) {
if (a[func(p[m-1-j])]) break;
++a[func(p[m-1-j])];
s=m-1-j;
}
}
if (maxlen<=e-s+1) {
maxlen=e-s+1;
res=p[s];
}
}
cout<<res<<endl;
}
}
hogeover30