結果

問題 No.6 使いものにならないハッシュ
ユーザー OKCH3COOHOKCH3COOH
提出日時 2019-10-23 22:02:11
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 141 ms / 5,000 ms
コード長 889 bytes
コンパイル時間 923 ms
コンパイル使用メモリ 10,764 KB
実行使用メモリ 11,720 KB
最終ジャッジ日時 2023-10-14 23:20:15
合計ジャッジ時間 4,931 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
7,960 KB
testcase_01 AC 16 ms
7,780 KB
testcase_02 AC 141 ms
10,872 KB
testcase_03 AC 35 ms
8,856 KB
testcase_04 AC 53 ms
9,808 KB
testcase_05 AC 51 ms
9,392 KB
testcase_06 AC 90 ms
10,544 KB
testcase_07 AC 77 ms
10,868 KB
testcase_08 AC 88 ms
10,816 KB
testcase_09 AC 100 ms
11,712 KB
testcase_10 AC 16 ms
7,880 KB
testcase_11 AC 38 ms
8,436 KB
testcase_12 AC 94 ms
10,004 KB
testcase_13 AC 90 ms
11,700 KB
testcase_14 AC 94 ms
11,720 KB
testcase_15 AC 81 ms
10,028 KB
testcase_16 AC 96 ms
11,432 KB
testcase_17 AC 119 ms
11,524 KB
testcase_18 AC 129 ms
10,772 KB
testcase_19 AC 113 ms
11,408 KB
testcase_20 AC 97 ms
10,632 KB
testcase_21 AC 28 ms
8,588 KB
testcase_22 AC 110 ms
11,320 KB
testcase_23 AC 94 ms
10,396 KB
testcase_24 AC 103 ms
10,700 KB
testcase_25 AC 80 ms
10,880 KB
testcase_26 AC 116 ms
10,780 KB
testcase_27 AC 104 ms
11,416 KB
testcase_28 AC 67 ms
10,140 KB
testcase_29 AC 118 ms
10,800 KB
testcase_30 AC 105 ms
10,444 KB
testcase_31 AC 102 ms
10,524 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

K = int(input())
N = int(input())

def primes(n):
    primeList = set()
    isPrime = [True] * (n + 1)
    for i in range(2, n + 1):
        if isPrime[i]:
            primeList.add(i)
            k = i * 2
            while k <= n:
                isPrime[k] = False
                k += i

    return primeList

primeK = primes(K - 1)
primeN = primes(N)
rangePrimes = list(primeN - primeK)
rangePrimes.sort()

def f(n):
    while sum(map(int, str(n))) >= 10:
        n = sum(map(int, str(n)))
    return sum(map(int, str(n)))

hashPrimes = [f(p) for p in rangePrimes]

maxLeng = 0
V = set()
M = len(hashPrimes)
ans = -1
right = 0

for left in range(M):
    while right < M and (not hashPrimes[right] in V):
        V.add(hashPrimes[right])
        right += 1

    if maxLeng <= len(V):
        maxLeng = len(V)
        ans = left

    V.remove(hashPrimes[left])

print(rangePrimes[ans])
0