結果

問題 No.12 限定された素数
ユーザー KudeKude
提出日時 2020-09-03 09:28:56
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 749 bytes
コンパイル時間 268 ms
コンパイル使用メモリ 86,664 KB
実行使用メモリ 116,396 KB
最終ジャッジ日時 2023-08-14 20:18:25
合計ジャッジ時間 11,783 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 382 ms
116,112 KB
testcase_02 AC 337 ms
116,204 KB
testcase_03 AC 421 ms
115,832 KB
testcase_04 WA -
testcase_05 AC 376 ms
116,104 KB
testcase_06 AC 377 ms
116,124 KB
testcase_07 AC 384 ms
116,260 KB
testcase_08 WA -
testcase_09 AC 367 ms
116,100 KB
testcase_10 WA -
testcase_11 AC 402 ms
116,116 KB
testcase_12 AC 393 ms
116,264 KB
testcase_13 AC 372 ms
116,272 KB
testcase_14 WA -
testcase_15 AC 379 ms
116,192 KB
testcase_16 AC 402 ms
116,172 KB
testcase_17 AC 346 ms
116,248 KB
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

n = int(input())

a = [False] * 10
for x in map(int, input().split()):
    a[x] = True

sieve = [True] * 5000002
ans = -1
k = 1
d = [False] * 10
for p in range(2, 5000002):
    if sieve[p] or p == 5000001:
        for i in range(p * p, 5000002, p):
            sieve[i] = False
        if p < 5000001:
            ok = True
            for x in map(int, str(p)):
                if not a[x]:
                    ok = False
                    break
        if not ok or p == 5000001:
            for i in range(10):
                if a[i] != d[i]:
                    break
            else:
                ans = max(ans, p - 1 - k)
            k = p + 1
        else:
            for x in map(int, str(p)):
                d[x] = True
print(ans)
0