結果

問題 No.6 使いものにならないハッシュ
ユーザー AEnAEn
提出日時 2022-12-13 01:34:50
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 105 ms / 5,000 ms
コード長 841 bytes
コンパイル時間 169 ms
コンパイル使用メモリ 82,432 KB
実行使用メモリ 78,848 KB
最終ジャッジ日時 2024-04-24 14:30:45
合計ジャッジ時間 4,105 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 40 ms
52,096 KB
testcase_01 AC 40 ms
51,840 KB
testcase_02 AC 99 ms
78,848 KB
testcase_03 AC 89 ms
76,800 KB
testcase_04 AC 84 ms
76,928 KB
testcase_05 AC 89 ms
76,800 KB
testcase_06 AC 100 ms
77,312 KB
testcase_07 AC 88 ms
77,440 KB
testcase_08 AC 93 ms
77,568 KB
testcase_09 AC 87 ms
77,824 KB
testcase_10 AC 40 ms
52,096 KB
testcase_11 AC 90 ms
76,288 KB
testcase_12 AC 105 ms
77,440 KB
testcase_13 AC 77 ms
73,088 KB
testcase_14 AC 87 ms
77,568 KB
testcase_15 AC 93 ms
77,440 KB
testcase_16 AC 91 ms
77,696 KB
testcase_17 AC 96 ms
77,696 KB
testcase_18 AC 104 ms
78,592 KB
testcase_19 AC 97 ms
77,696 KB
testcase_20 AC 101 ms
77,696 KB
testcase_21 AC 74 ms
74,496 KB
testcase_22 AC 94 ms
77,568 KB
testcase_23 AC 96 ms
77,312 KB
testcase_24 AC 96 ms
77,440 KB
testcase_25 AC 95 ms
77,312 KB
testcase_26 AC 98 ms
77,568 KB
testcase_27 AC 94 ms
77,568 KB
testcase_28 AC 90 ms
76,928 KB
testcase_29 AC 100 ms
77,824 KB
testcase_30 AC 99 ms
77,824 KB
testcase_31 AC 96 ms
77,696 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def smallest_prime_factors(n):
    spf = [0]*(n+1)
    for i in range(n+1):
        spf[i] = i
    for i in range(2,n+1):
        if i*i>n:
            break
        if spf[i] == i:
            for j in range(i*i, n+1, i):
                if spf[j] == j:
                    spf[j] = i
    return spf

K = int(input())
N = int(input())
spf = smallest_prime_factors(N)

hash = []
prime = []
for i in range(K,N+1):
    if spf[i]==i and i!=1:
        num = i
        prime.append(num)
        while len(str(num))>1:
            num = sum([int(j) for j in str(num)])
        hash.append(num)
            
l,r = 0,0
res = 0
ans = 0
s = set()
while l<len(hash):
    while r<len(hash) and hash[r] not in s:
        s.add(hash[r])
        r += 1
    if r-l>=res:
        res = r-l
        ans = prime[l]
    s.remove(hash[l])
    l += 1
print(ans)

0