結果

問題 No.6 使いものにならないハッシュ
ユーザー gaokai2050gaokai2050
提出日時 2022-11-09 11:10:51
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 3 ms / 5,000 ms
コード長 828 bytes
コンパイル時間 2,367 ms
コンパイル使用メモリ 164,576 KB
実行使用メモリ 4,484 KB
最終ジャッジ日時 2023-09-29 23:24:06
合計ジャッジ時間 2,896 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 3 ms
4,376 KB
testcase_03 AC 3 ms
4,376 KB
testcase_04 AC 3 ms
4,380 KB
testcase_05 AC 3 ms
4,376 KB
testcase_06 AC 3 ms
4,376 KB
testcase_07 AC 3 ms
4,380 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 3 ms
4,376 KB
testcase_12 AC 3 ms
4,380 KB
testcase_13 AC 2 ms
4,428 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 3 ms
4,480 KB
testcase_16 AC 3 ms
4,376 KB
testcase_17 AC 3 ms
4,380 KB
testcase_18 AC 3 ms
4,380 KB
testcase_19 AC 3 ms
4,376 KB
testcase_20 AC 3 ms
4,376 KB
testcase_21 AC 2 ms
4,448 KB
testcase_22 AC 3 ms
4,380 KB
testcase_23 AC 2 ms
4,480 KB
testcase_24 AC 3 ms
4,380 KB
testcase_25 AC 2 ms
4,380 KB
testcase_26 AC 3 ms
4,380 KB
testcase_27 AC 3 ms
4,376 KB
testcase_28 AC 3 ms
4,484 KB
testcase_29 AC 3 ms
4,376 KB
testcase_30 AC 3 ms
4,380 KB
testcase_31 AC 3 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include "bits/stdc++.h"
using namespace std;
const int N=200010;
int a,b,c,p[N],h[N],is_p[N],l,ans,vis[20];
int h0(int n) {
    while (n>=10) {
        int m=0;
        while (n) m+=n%10,n/=10;
        n=m;
    }
    return n;
}
int main() {
    memset(is_p,0x3f,sizeof(is_p));
    is_p[0]=is_p[1]=0;
    for (int i=2;i*i<N;++i)
        if (is_p[i])
            for (int j=i*i;j<N;j+=i)
                is_p[j]=0;
    cin>>a>>b;
    for (int i=a;i<=b;++i)
        if (is_p[i]) ++c,p[c]=i,h[c]=h0(i);
    assert(c>=1);
    for (int i=1,j=2;i<=c;++i) {
        vis[h[i]]=1;
        if (i==j) ++j;
        while (j<=c) {
            if (vis[h[j]]) break;
            vis[h[j]]=1;
            ++j;
        }
        if (l<=j-i) l=j-i,ans=p[i];
        if (j>c) break;
        vis[h[i]]=0;
    }
    cout<<ans<<endl;
    return 0;
}
0