結果
| 問題 |
No.12 限定された素数
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2022-07-04 17:52:06 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 950 bytes |
| コンパイル時間 | 567 ms |
| コンパイル使用メモリ | 82,048 KB |
| 実行使用メモリ | 140,728 KB |
| 最終ジャッジ日時 | 2024-12-14 09:17:01 |
| 合計ジャッジ時間 | 13,553 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 23 WA * 3 |
ソースコード
from cmath import e
N = 5000100
isprime = [True] * N
isprime[0] = isprime[1] = False
for i in range(2, int(N ** 0.5 + 1)):
if not isprime[i]:
continue
for j in range(i * i, N, i):
isprime[j] = False
lst = [i for i in range(N) if isprime[i]]
while lst[-1] >= 5000000:
lst.pop()
n = int(input())
A = list(map(int, input().split()))
tf = [False] * 10
for a in A:
tf[a] = True
bef = 0
ans = -1
used = [False] * 10
tot = 0
for a in lst:
ok = True
se = set()
for b in str(a):
b = int(b)
if tf[b]:
se.add(b)
else:
ok = False
break
if ok:
for b in se:
if not used[b]:
used[b] = True
tot += 1
else:
if tot == n:
used = [False] * 10
ans = max(ans, a - bef - 2)
tot = 0
bef = a
if tot == n:
ans = max(ans, 5000001 - bef - 2)
print(ans)