結果

問題 No.6 使いものにならないハッシュ
ユーザー yuki2006yuki2006
提出日時 2015-06-20 17:56:53
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 256 ms / 5,000 ms
コード長 1,084 bytes
コンパイル時間 109 ms
コンパイル使用メモリ 11,012 KB
実行使用メモリ 10,680 KB
最終ジャッジ日時 2023-10-14 22:53:03
合計ジャッジ時間 6,148 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 15 ms
8,320 KB
testcase_01 AC 14 ms
8,240 KB
testcase_02 AC 251 ms
10,680 KB
testcase_03 AC 55 ms
8,644 KB
testcase_04 AC 85 ms
9,240 KB
testcase_05 AC 85 ms
9,140 KB
testcase_06 AC 162 ms
9,872 KB
testcase_07 AC 121 ms
9,692 KB
testcase_08 AC 146 ms
9,924 KB
testcase_09 AC 158 ms
10,500 KB
testcase_10 AC 15 ms
8,336 KB
testcase_11 AC 58 ms
8,804 KB
testcase_12 AC 173 ms
10,060 KB
testcase_13 AC 141 ms
10,472 KB
testcase_14 AC 153 ms
10,460 KB
testcase_15 AC 146 ms
9,828 KB
testcase_16 AC 157 ms
10,340 KB
testcase_17 AC 210 ms
10,576 KB
testcase_18 AC 256 ms
10,628 KB
testcase_19 AC 216 ms
10,496 KB
testcase_20 AC 195 ms
10,292 KB
testcase_21 AC 38 ms
8,620 KB
testcase_22 AC 194 ms
10,380 KB
testcase_23 AC 178 ms
10,068 KB
testcase_24 AC 190 ms
10,340 KB
testcase_25 AC 135 ms
9,992 KB
testcase_26 AC 209 ms
10,608 KB
testcase_27 AC 192 ms
10,512 KB
testcase_28 AC 115 ms
9,560 KB
testcase_29 AC 228 ms
10,536 KB
testcase_30 AC 202 ms
10,244 KB
testcase_31 AC 196 ms
10,396 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

used = [0] * 10

for x in range(10):
    used[x] = False

K = int(input())
N = int(input())
num = [2]
prime = []
prime1 = []

table = [True] * (N + 1)

for i in range(2, N + 1):
    if not table[i]:
        continue
    k = i + i
    while k < N + 1:
        table[k] = False
        k += i

    num.append(i)



for x in range(len(num)):
    if num[x] >= K and num[x] != 0:
        prime1.append(num[x])
        while num[x] >= 10:
            s = str(num[x])
            num[x] = 0
            for y in range(len(s)):
                num[x] += int(s[y])
        prime.append(num[x])

length = 0
start = 0
best_s = 0
best_l = 0

i = 0
while i < len(prime):
    if not used[prime[i]]:
        used[prime[i]] = True
        length += 1
        i += 1
    else:
        if start >= len(prime): break
        while start < i and prime[start] != prime[i]:
            used[prime[start]] = False
            start += 1
        start += 1
        length = i - start + 1
        i += 1

    best_l = max(best_l, length)
    if best_l == length:
        best_s = start

print(prime1[best_s])
0