結果
| 問題 |
No.6 使いものにならないハッシュ
|
| コンテスト | |
| ユーザー |
tnodino
|
| 提出日時 | 2022-01-30 15:16:29 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 91 ms / 5,000 ms |
| コード長 | 950 bytes |
| コンパイル時間 | 179 ms |
| コンパイル使用メモリ | 81,920 KB |
| 実行使用メモリ | 80,000 KB |
| 最終ジャッジ日時 | 2024-06-11 08:17:41 |
| 合計ジャッジ時間 | 3,809 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 32 |
ソースコード
from collections import defaultdict
def SieveofEratosthenes(N):
P = [0] * (N+1)
P[0] = P[1] = -1
for i in range(2,N+1):
if P[i] == 0:
k = i
while k <= N:
P[k] = i
k += i
P[i] = 0
return P
def hash(N):
if N in dic:
return dic[N]
x = N
S = 0
while x:
S += x % 10
x //= 10
dic[N] = hash(S)
return dic[N]
K = int(input())
N = int(input())
P = SieveofEratosthenes(N)
C = []
for i in range(K,N+1):
if P[i] == 0:
C.append(i)
dic = {}
for i in range(10):
dic[i] = i
M = len(C)
F = []
for i in range(M):
F.append(hash(C[i]))
dic = defaultdict(int)
Left = 0
Length = 0
ans = 0
for Right in range(M):
dic[F[Right]] += 1
while dic[F[Right]] >= 2:
dic[F[Left]] -= 1
Left += 1
if Right - Left + 1 >= Length:
Length = Right - Left + 1
ans = C[Left]
print(ans)
tnodino