結果

問題 No.6 使いものにならないハッシュ
ユーザー taisuketaisuke
提出日時 2023-02-19 20:01:00
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 82 ms / 5,000 ms
コード長 1,000 bytes
コンパイル時間 143 ms
コンパイル使用メモリ 11,064 KB
実行使用メモリ 9,892 KB
最終ジャッジ日時 2023-09-28 00:07:19
合計ジャッジ時間 3,953 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 14 ms
8,624 KB
testcase_01 AC 13 ms
8,380 KB
testcase_02 AC 78 ms
9,820 KB
testcase_03 AC 26 ms
8,768 KB
testcase_04 AC 39 ms
8,980 KB
testcase_05 AC 34 ms
8,792 KB
testcase_06 AC 54 ms
9,240 KB
testcase_07 AC 51 ms
9,236 KB
testcase_08 AC 54 ms
9,304 KB
testcase_09 AC 67 ms
9,892 KB
testcase_10 AC 13 ms
8,504 KB
testcase_11 AC 27 ms
8,768 KB
testcase_12 AC 57 ms
9,240 KB
testcase_13 AC 60 ms
9,648 KB
testcase_14 AC 62 ms
9,676 KB
testcase_15 AC 52 ms
9,368 KB
testcase_16 AC 62 ms
9,656 KB
testcase_17 AC 73 ms
9,804 KB
testcase_18 AC 82 ms
9,736 KB
testcase_19 AC 71 ms
9,708 KB
testcase_20 AC 62 ms
9,596 KB
testcase_21 AC 22 ms
8,644 KB
testcase_22 AC 70 ms
9,836 KB
testcase_23 AC 57 ms
9,240 KB
testcase_24 AC 63 ms
9,656 KB
testcase_25 AC 51 ms
9,364 KB
testcase_26 AC 71 ms
9,824 KB
testcase_27 AC 66 ms
9,716 KB
testcase_28 AC 43 ms
8,972 KB
testcase_29 AC 76 ms
9,888 KB
testcase_30 AC 65 ms
9,720 KB
testcase_31 AC 65 ms
9,788 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def Eratosthenes(n):
    sieve = [True] * ((n + 1) // 2)
    for i in range(1, (int(n ** 0.5) + 1) // 2):
        if sieve[i]:
            for j in range(i * 3 + 1, (n + 1) // 2, i * 2 + 1):
                sieve[j] = False
    res = [i * 2 + 1 for i, s in enumerate(sieve) if s]
    res[0] = 2
    return res


def f(n):
    if n < 10:
        return n
    ret = sum(list(map(int, str(n))))
    return f(ret)


k = int(input())
n = int(input())
prime = Eratosthenes(n)
val = list()
for p in prime:
    val.append(f(p))

start = 0
for i in range(len(prime)):
    if prime[i] >= k:
        start = i
        break

used = [False] * 10
ans = prime[start]
maxlen = 0
right = start
for left in range(start, len(val)):
    while right < len(val) and used[val[right]] == False:
        used[val[right]] = True
        right += 1
    if maxlen <= right - left + 1:
        maxlen = right - left + 1
        ans = prime[left]

    if left == right:
        right += 1
    used[val[left]] = False

print(ans)
0