結果

問題 No.6 使いものにならないハッシュ
ユーザー nagitaosunagitaosu
提出日時 2020-03-13 03:52:10
言語 Python3
(3.11.6 + numpy 1.26.0 + scipy 1.11.3)
結果
AC  
実行時間 108 ms / 5,000 ms
コード長 994 bytes
コンパイル時間 136 ms
コンパイル使用メモリ 11,048 KB
実行使用メモリ 10,808 KB
最終ジャッジ日時 2023-10-14 23:22:30
合計ジャッジ時間 3,085 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 15 ms
8,416 KB
testcase_01 AC 15 ms
7,820 KB
testcase_02 AC 108 ms
10,808 KB
testcase_03 AC 29 ms
8,652 KB
testcase_04 AC 35 ms
8,896 KB
testcase_05 AC 41 ms
8,940 KB
testcase_06 AC 64 ms
9,812 KB
testcase_07 AC 42 ms
9,448 KB
testcase_08 AC 59 ms
9,788 KB
testcase_09 AC 39 ms
9,972 KB
testcase_10 AC 17 ms
8,588 KB
testcase_11 AC 33 ms
8,708 KB
testcase_12 AC 80 ms
9,888 KB
testcase_13 AC 32 ms
9,676 KB
testcase_14 AC 40 ms
9,524 KB
testcase_15 AC 65 ms
9,540 KB
testcase_16 AC 51 ms
9,520 KB
testcase_17 AC 83 ms
10,304 KB
testcase_18 AC 107 ms
10,600 KB
testcase_19 AC 83 ms
10,328 KB
testcase_20 AC 78 ms
9,768 KB
testcase_21 AC 25 ms
8,448 KB
testcase_22 AC 78 ms
9,980 KB
testcase_23 AC 78 ms
9,720 KB
testcase_24 AC 72 ms
10,072 KB
testcase_25 AC 49 ms
9,620 KB
testcase_26 AC 87 ms
10,248 KB
testcase_27 AC 70 ms
10,088 KB
testcase_28 AC 51 ms
9,316 KB
testcase_29 AC 96 ms
10,416 KB
testcase_30 AC 86 ms
9,972 KB
testcase_31 AC 80 ms
9,984 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#!/usr/bin/env python3
import sys
input = sys.stdin.readline

# O(nloglogn)
def primes(k, n):
    is_prime = [True] * (n + 1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(n**0.5) + 1):
        if not is_prime[i]:
            continue
        for j in range(i * 2, n + 1, i):
            is_prime[j] = False
    return [i for i in range(k, n + 1) if is_prime[i]]

def hash(n):
    while n >= 10:
        t = 0
        while n > 0:
            t += n % 10
            n //= 10
        n = t
    return n

k = int(input())
n = int(input())

p = primes(k, n)
d = []
for item in p:
    digits = sum([int(dgt) for dgt in str(item)])
    d.append(hash(item))
max_length = 0
ans = 0
for i, item in enumerate(d):
    cnt = [0] * 10
    cnt[item] += 1
    for j in range(i + 1, len(d) + 1):
        if j == len(d) or cnt[d[j]] > 0:
            break
        else:
            cnt[d[j]] += 1
    if j - i >= max_length:
        ans = i
        max_length = j - i
print(p[ans])
0