結果
| 問題 | No.12 限定された素数 | 
| コンテスト | |
| ユーザー |  | 
| 提出日時 | 2022-07-04 17:54:05 | 
| 言語 | PyPy3 (7.3.15) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 479 ms / 5,000 ms | 
| コード長 | 943 bytes | 
| コンパイル時間 | 871 ms | 
| コンパイル使用メモリ | 82,168 KB | 
| 実行使用メモリ | 140,848 KB | 
| 最終ジャッジ日時 | 2024-12-14 09:19:23 | 
| 合計ジャッジ時間 | 12,864 ms | 
| ジャッジサーバーID (参考情報) | judge4 / judge2 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 26 | 
ソースコード
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:
            ans = max(ans, a - bef - 2)
        used = [False] * 10
        tot = 0
        bef = a
if tot == n:
    ans = max(ans, 5000001 - bef - 2)
print(ans)
            
            
            
        