結果

問題 No.6 使いものにならないハッシュ
ユーザー warashiwarashi
提出日時 2015-02-13 00:57:44
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 436 ms / 5,000 ms
コード長 1,181 bytes
コンパイル時間 246 ms
コンパイル使用メモリ 10,968 KB
実行使用メモリ 10,392 KB
最終ジャッジ日時 2023-10-14 22:49:31
合計ジャッジ時間 5,746 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
8,192 KB
testcase_01 AC 16 ms
8,312 KB
testcase_02 AC 436 ms
10,200 KB
testcase_03 AC 31 ms
8,504 KB
testcase_04 AC 45 ms
8,848 KB
testcase_05 AC 66 ms
8,704 KB
testcase_06 AC 137 ms
9,564 KB
testcase_07 AC 61 ms
9,280 KB
testcase_08 AC 105 ms
9,456 KB
testcase_09 AC 52 ms
9,868 KB
testcase_10 AC 15 ms
8,248 KB
testcase_11 AC 38 ms
8,496 KB
testcase_12 AC 223 ms
9,620 KB
testcase_13 AC 47 ms
9,444 KB
testcase_14 AC 52 ms
9,668 KB
testcase_15 AC 145 ms
9,360 KB
testcase_16 AC 74 ms
9,600 KB
testcase_17 AC 204 ms
10,028 KB
testcase_18 AC 379 ms
10,152 KB
testcase_19 AC 201 ms
9,976 KB
testcase_20 AC 175 ms
9,732 KB
testcase_21 AC 24 ms
8,400 KB
testcase_22 AC 182 ms
9,832 KB
testcase_23 AC 190 ms
9,616 KB
testcase_24 AC 177 ms
9,880 KB
testcase_25 AC 74 ms
9,332 KB
testcase_26 AC 257 ms
10,136 KB
testcase_27 AC 143 ms
9,844 KB
testcase_28 AC 89 ms
8,968 KB
testcase_29 AC 281 ms
10,392 KB
testcase_30 AC 258 ms
9,972 KB
testcase_31 AC 185 ms
9,876 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#!/usr/bin/env python3
from itertools import dropwhile


def sqrt_floor(n):
    l = 5 * n
    r = 5
    sqrt = 0
    while l > r:
        sqrt += 1
        l = l - r
        r += 10
    return sqrt


def sieve_of_eratosthenes(max):
    is_prime = [True] * (max + 1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, sqrt_floor(max) + 1):
        if not is_prime[i]:
            continue
        for j in range(i * i, max + 1, i):
            is_prime[j] = False
    return filter(lambda x: is_prime[x], range(max + 1))


def digital_root(n):
    if n == 0:
        return 0
    if n % 9 == 0:
        return 9
    return n % 9


def length(digitals, start_index):
    appeared = []
    count = 0
    for i in digitals[start_index:]:
        if i in appeared:
            break
        appeared.append(i)
        count += 1
    return count

K = int(input())
N = int(input())
primes = tuple(dropwhile(lambda x: x < K, sieve_of_eratosthenes(N)))
digitals = tuple(map(digital_root, primes))
maxlength = 0
index = 0
for i in range(len(digitals)):
    tmp = length(digitals, i)
    if tmp >= maxlength:
        maxlength = tmp
        index = i
print(primes[index])
0