結果

問題 No.6 使いものにならないハッシュ
ユーザー 👑 NachiaNachia
提出日時 2020-09-27 11:58:13
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 6 ms / 5,000 ms
コード長 1,005 bytes
コンパイル時間 1,623 ms
コンパイル使用メモリ 167,284 KB
実行使用メモリ 4,732 KB
最終ジャッジ日時 2023-10-14 23:27:07
合計ジャッジ時間 3,090 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
4,496 KB
testcase_01 AC 4 ms
4,400 KB
testcase_02 AC 5 ms
4,652 KB
testcase_03 AC 5 ms
4,424 KB
testcase_04 AC 5 ms
4,660 KB
testcase_05 AC 5 ms
4,484 KB
testcase_06 AC 5 ms
4,464 KB
testcase_07 AC 5 ms
4,444 KB
testcase_08 AC 5 ms
4,428 KB
testcase_09 AC 4 ms
4,368 KB
testcase_10 AC 4 ms
4,352 KB
testcase_11 AC 5 ms
4,356 KB
testcase_12 AC 5 ms
4,560 KB
testcase_13 AC 4 ms
4,348 KB
testcase_14 AC 5 ms
4,352 KB
testcase_15 AC 5 ms
4,732 KB
testcase_16 AC 5 ms
4,444 KB
testcase_17 AC 5 ms
4,644 KB
testcase_18 AC 6 ms
4,432 KB
testcase_19 AC 5 ms
4,460 KB
testcase_20 AC 5 ms
4,644 KB
testcase_21 AC 5 ms
4,476 KB
testcase_22 AC 5 ms
4,508 KB
testcase_23 AC 5 ms
4,412 KB
testcase_24 AC 5 ms
4,440 KB
testcase_25 AC 5 ms
4,360 KB
testcase_26 AC 5 ms
4,544 KB
testcase_27 AC 5 ms
4,488 KB
testcase_28 AC 4 ms
4,356 KB
testcase_29 AC 5 ms
4,476 KB
testcase_30 AC 5 ms
4,548 KB
testcase_31 AC 5 ms
4,400 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
#define rep(i,n) for(int i=0; i<(n); i++)

int K, N;
int H[200001];
bool sieve[200001] = {};
vector<int> A;

int main() {
    int K, N; cin >> K >> N;

    rep(i, 10) H[i] = i;
    for (int i = 10; i <= 200000; i++) {
        int p = i, buf = 0;
        while (p) { buf += p % 10; p /= 10; }
        H[i] = H[buf];
    }

    sieve[0] = sieve[1] = true;
    for (int i = 2; i < 1000; i++) {
        if (sieve[i]) continue;
        for (int j = i * i; j <= 200000; j += i) sieve[j] = true;
    }

    for (int i = K; i <= N; i++) if (!sieve[i]) A.push_back(i);

    int ans = 0, len = 0;
    rep(i, A.size()) {
        bitset<10> f;
        int lentmp = 0;
        for (int j = i; j < A.size(); j++) {
            if (f.test(H[A[j]])) break;
            lentmp++;
            f.set(H[A[j]]);
        }
        if (len <= lentmp) { len = lentmp; ans = A[i]; }
    }

    cout << ans << endl;

    return 0;
}
0