結果

問題 No.6 使いものにならないハッシュ
ユーザー hogeover30hogeover30
提出日時 2015-02-12 20:12:39
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 5 ms / 5,000 ms
コード長 961 bytes
コンパイル時間 719 ms
コンパイル使用メモリ 60,136 KB
実行使用メモリ 5,064 KB
最終ジャッジ日時 2023-10-14 22:48:38
合計ジャッジ時間 1,805 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
4,352 KB
testcase_01 AC 2 ms
4,352 KB
testcase_02 AC 5 ms
5,064 KB
testcase_03 AC 2 ms
4,352 KB
testcase_04 AC 3 ms
4,356 KB
testcase_05 AC 3 ms
4,352 KB
testcase_06 AC 3 ms
4,752 KB
testcase_07 AC 3 ms
4,356 KB
testcase_08 AC 3 ms
4,496 KB
testcase_09 AC 2 ms
4,352 KB
testcase_10 AC 2 ms
4,352 KB
testcase_11 AC 3 ms
4,444 KB
testcase_12 AC 4 ms
4,772 KB
testcase_13 AC 3 ms
4,356 KB
testcase_14 AC 3 ms
4,444 KB
testcase_15 AC 3 ms
4,564 KB
testcase_16 AC 3 ms
4,368 KB
testcase_17 AC 3 ms
4,800 KB
testcase_18 AC 4 ms
5,012 KB
testcase_19 AC 3 ms
4,660 KB
testcase_20 AC 4 ms
4,804 KB
testcase_21 AC 3 ms
4,356 KB
testcase_22 AC 3 ms
4,948 KB
testcase_23 AC 4 ms
4,792 KB
testcase_24 AC 4 ms
4,848 KB
testcase_25 AC 3 ms
4,528 KB
testcase_26 AC 3 ms
5,052 KB
testcase_27 AC 3 ms
4,864 KB
testcase_28 AC 3 ms
4,440 KB
testcase_29 AC 4 ms
4,816 KB
testcase_30 AC 4 ms
4,740 KB
testcase_31 AC 4 ms
4,668 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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;
    }
}
0