結果

問題 No.12 限定された素数
ユーザー KudeKude
提出日時 2020-09-03 09:32:25
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 429 ms / 5,000 ms
コード長 778 bytes
コンパイル時間 357 ms
コンパイル使用メモリ 87,084 KB
実行使用メモリ 116,788 KB
最終ジャッジ日時 2023-08-14 20:19:22
合計ジャッジ時間 12,134 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 376 ms
116,156 KB
testcase_01 AC 413 ms
116,280 KB
testcase_02 AC 368 ms
116,296 KB
testcase_03 AC 418 ms
116,000 KB
testcase_04 AC 386 ms
116,056 KB
testcase_05 AC 410 ms
116,580 KB
testcase_06 AC 399 ms
116,376 KB
testcase_07 AC 429 ms
116,428 KB
testcase_08 AC 386 ms
116,408 KB
testcase_09 AC 392 ms
116,168 KB
testcase_10 AC 412 ms
116,544 KB
testcase_11 AC 414 ms
116,220 KB
testcase_12 AC 400 ms
116,096 KB
testcase_13 AC 397 ms
116,184 KB
testcase_14 AC 405 ms
116,280 KB
testcase_15 AC 385 ms
116,244 KB
testcase_16 AC 427 ms
116,496 KB
testcase_17 AC 393 ms
116,196 KB
testcase_18 AC 371 ms
116,212 KB
testcase_19 AC 372 ms
116,004 KB
testcase_20 AC 372 ms
116,160 KB
testcase_21 AC 414 ms
116,696 KB
testcase_22 AC 380 ms
116,152 KB
testcase_23 AC 389 ms
116,372 KB
testcase_24 AC 374 ms
116,116 KB
testcase_25 AC 416 ms
116,788 KB
権限があれば一括ダウンロードができます

ソースコード

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
            d = [False] * 10
        else:
            for x in map(int, str(p)):
                d[x] = True
print(ans)
0