結果

問題 No.6 使いものにならないハッシュ
ユーザー Woo-CieWoo-Cie
提出日時 2019-03-23 17:24:03
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 439 ms / 5,000 ms
コード長 942 bytes
コンパイル時間 102 ms
コンパイル使用メモリ 11,032 KB
実行使用メモリ 9,112 KB
最終ジャッジ日時 2023-10-14 23:16:19
合計ジャッジ時間 7,556 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 15 ms
8,488 KB
testcase_01 AC 15 ms
8,308 KB
testcase_02 AC 439 ms
9,092 KB
testcase_03 AC 54 ms
8,552 KB
testcase_04 AC 80 ms
8,468 KB
testcase_05 AC 91 ms
8,664 KB
testcase_06 AC 221 ms
8,804 KB
testcase_07 AC 124 ms
8,532 KB
testcase_08 AC 198 ms
8,684 KB
testcase_09 AC 84 ms
8,384 KB
testcase_10 AC 15 ms
8,440 KB
testcase_11 AC 59 ms
8,628 KB
testcase_12 AC 250 ms
8,776 KB
testcase_13 AC 55 ms
8,320 KB
testcase_14 AC 87 ms
8,524 KB
testcase_15 AC 204 ms
8,808 KB
testcase_16 AC 153 ms
8,628 KB
testcase_17 AC 329 ms
8,712 KB
testcase_18 AC 437 ms
9,112 KB
testcase_19 AC 318 ms
8,928 KB
testcase_20 AC 270 ms
8,780 KB
testcase_21 AC 39 ms
8,408 KB
testcase_22 AC 312 ms
8,744 KB
testcase_23 AC 257 ms
8,876 KB
testcase_24 AC 281 ms
8,900 KB
testcase_25 AC 155 ms
8,656 KB
testcase_26 AC 355 ms
8,792 KB
testcase_27 AC 273 ms
8,808 KB
testcase_28 AC 150 ms
8,572 KB
testcase_29 AC 386 ms
8,836 KB
testcase_30 AC 316 ms
8,944 KB
testcase_31 AC 295 ms
8,792 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#!/usr/bin/env python3
# -*- coding: utf-8-*-
import math

def h(n):
    r = n%10
    while n >= 10:
        n //= 10
        r += n%10
    if r >= 10:
        r = h(r)
    return r

def isp(n):
    if n == 1:
        return False
    for i in range(2, math.floor(math.sqrt(n))+1):
        if n % i == 0:
            return False
    return True

if __name__ == '__main__':
    k = int(input())
    n = int(input())
    l = [-1,-1,-1,-1,-1,-1,-1,-1,-1,-1]
    p = []
    s = 0
    a = 0
    ap = 2
    ii = 0
    for i in range(k, n+1):
        if isp(i):
            p.append(i)
            ha = h(i)
            if l[ha] != -1:
                if s <= l[ha]:
                    d = ii - s
                    if a <= d:
                        a = d
                        ap = p[s]
                    s = l[ha]+1
            l[ha] = ii
            ii += 1
    d = len(p) - s
    if a <= d:
        a = d
        ap = p[s]
    print(ap)
0