結果
| 問題 |
No.6 使いものにならないハッシュ
|
| コンテスト | |
| ユーザー |
しらっ亭
|
| 提出日時 | 2015-08-30 18:39:11 |
| 言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
| 結果 |
AC
|
| 実行時間 | 68 ms / 5,000 ms |
| コード長 | 977 bytes |
| コンパイル時間 | 422 ms |
| コンパイル使用メモリ | 12,416 KB |
| 実行使用メモリ | 13,056 KB |
| 最終ジャッジ日時 | 2024-09-16 16:29:26 |
| 合計ジャッジ時間 | 2,943 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 32 |
ソースコード
def sieve(n):
s = [True] * n
def mark(x):
for i in range(x + x, n, x):
s[i] = False
for x in range(2, int(n ** 0.5) + 1):
if s[x]:
mark(x)
return [i for i in range(n) if s[i] and i > 1]
def dr(n):
if n == 0:
return 0
if n % 9 == 0:
return 9
else:
return n % 9
def solve():
K = int(input())
N = int(input())
hc = [0] * 10
tc = 0
ps = [p for p in sieve(N + 1) if p >= K]
i = j = 0
ma = 0
mi = 0
while i < len(ps):
if tc == 0 and j < len(ps):
h = dr(ps[j])
hc[h] += 1
if hc[h] >= 2:
tc += 1
j += 1
else:
h = dr(ps[i])
hc[h] -= 1
if hc[h] == 1:
tc -= 1
i += 1
if tc == 0 and j - i >= ma:
ma = j - i
mi = i
print(ps[mi])
if __name__ == '__main__':
solve()
しらっ亭