結果
問題 |
No.6 使いものにならないハッシュ
|
ユーザー |
|
提出日時 | 2019-10-27 20:20:15 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 99 ms / 5,000 ms |
コード長 | 907 bytes |
コンパイル時間 | 333 ms |
コンパイル使用メモリ | 82,048 KB |
実行使用メモリ | 77,696 KB |
最終ジャッジ日時 | 2024-09-16 16:52:55 |
合計ジャッジ時間 | 4,141 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 32 |
ソースコード
from collections import defaultdict def era(n): is_prime = [True] * (n+1) is_prime[0] = False is_prime[1] = False for i in range(2, int(n**0.5)+1): if not is_prime[i]: continue for j in range(2*i, n+1, i): is_prime[j] = False return [i for i in range(K, n+1) if is_prime[i]] def calc(n): if len(str(n)) == 1: return n s = 0 for ni in str(n): s += int(ni) return calc(s) K = int(input()) N = int(input()) primes = era(N) hashed = [calc(p) for p in primes] r = 0 length = 0 d = defaultdict(int) for l in range(len(hashed)): while r < len(hashed) and d[hashed[r]] == 0: d[hashed[r]] += 1 r += 1 if length <= r-l: length = r-l ans = primes[l] if l == r: r += 1 d[hashed[l]] -= 1 l += 1 print(ans)