結果
問題 | No.6 使いものにならないハッシュ |
ユーザー |
![]() |
提出日時 | 2023-10-02 08:58:07 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 83 ms / 5,000 ms |
コード長 | 820 bytes |
コンパイル時間 | 274 ms |
コンパイル使用メモリ | 82,372 KB |
実行使用メモリ | 80,544 KB |
最終ジャッジ日時 | 2024-07-26 13:36:49 |
合計ジャッジ時間 | 3,771 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 32 |
ソースコード
from math import sqrt, ceildef 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] = Falsefor 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] * 10def f(x):while len(str(x)) != 1:v = 0while x:v += x % 10x //= 10x = vreturn xans = -1maxv = -1for s in S:if s < K or s > N:continueq = f(s)seen[q] += 1Q.append(s)while seen[q] == 2:seen[f(Q.popleft())] -= 1if len(Q) >= maxv:ans = Q[0]maxv = len(Q)print(ans)