結果
| 問題 | No.6 使いものにならないハッシュ |
| コンテスト | |
| ユーザー |
rlangevin
|
| 提出日時 | 2023-10-02 08:58:07 |
| 言語 | PyPy3 (7.3.23 + ACL) |
| 結果 |
AC
不安定
|
| 実行時間 | 103 ms / 5,000 ms |
| + 38µs | |
| コード長 | 820 bytes |
| 記録 | |
| コンパイル時間 | 260 ms |
| コンパイル使用メモリ | 96,104 KB |
| 実行使用メモリ | 88,960 KB |
| 最終ジャッジ日時 | 2026-08-24 11:01:23 |
| 合計ジャッジ時間 | 5,691 ms |
|
ジャッジサーバーID (参考情報) |
judge1_0 / judge3_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 32 |
ソースコード
from math import sqrt, ceil
def Sieve(n):
lst = [True] * (n + 1)
S = set()
for i in range(2, ceil(sqrt(n)) + 1):
if lst[i]:
for j in range(2 * i, n + 1, i):
lst[j] = False
for i in range(2, n + 1):
if lst[i]:
S.add(i)
return sorted(list(S))
K = int(input())
N = int(input())
S = Sieve(N + 5)
from collections import *
Q = deque()
seen = [0] * 10
def f(x):
while len(str(x)) != 1:
v = 0
while x:
v += x % 10
x //= 10
x = v
return x
ans = -1
maxv = -1
for s in S:
if s < K or s > N:
continue
q = f(s)
seen[q] += 1
Q.append(s)
while seen[q] == 2:
seen[f(Q.popleft())] -= 1
if len(Q) >= maxv:
ans = Q[0]
maxv = len(Q)
print(ans)
rlangevin