結果

問題 No.12 限定された素数
ユーザー 👑 rin204rin204
提出日時 2022-07-04 17:52:06
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 950 bytes
コンパイル時間 1,062 ms
コンパイル使用メモリ 87,224 KB
実行使用メモリ 141,908 KB
最終ジャッジ日時 2023-08-21 01:37:33
合計ジャッジ時間 13,800 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 384 ms
141,500 KB
testcase_01 AC 392 ms
141,700 KB
testcase_02 AC 380 ms
141,716 KB
testcase_03 AC 464 ms
141,412 KB
testcase_04 AC 373 ms
141,720 KB
testcase_05 AC 416 ms
141,736 KB
testcase_06 AC 407 ms
141,468 KB
testcase_07 AC 450 ms
141,780 KB
testcase_08 WA -
testcase_09 AC 390 ms
141,768 KB
testcase_10 WA -
testcase_11 AC 450 ms
141,732 KB
testcase_12 AC 420 ms
141,752 KB
testcase_13 AC 416 ms
141,460 KB
testcase_14 AC 403 ms
141,876 KB
testcase_15 AC 397 ms
141,232 KB
testcase_16 AC 432 ms
141,788 KB
testcase_17 AC 356 ms
140,912 KB
testcase_18 AC 369 ms
141,512 KB
testcase_19 AC 357 ms
141,220 KB
testcase_20 AC 386 ms
141,492 KB
testcase_21 AC 381 ms
141,692 KB
testcase_22 AC 382 ms
141,844 KB
testcase_23 AC 375 ms
141,648 KB
testcase_24 AC 373 ms
141,428 KB
testcase_25 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

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)
0