結果

問題 No.12 限定された素数
ユーザー rlangevinrlangevin
提出日時 2023-10-24 12:28:28
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,164 ms / 5,000 ms
コード長 837 bytes
コンパイル時間 173 ms
コンパイル使用メモリ 81,740 KB
実行使用メモリ 170,016 KB
最終ジャッジ日時 2023-10-24 12:28:44
合計ジャッジ時間 15,195 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 434 ms
169,216 KB
testcase_01 AC 444 ms
169,524 KB
testcase_02 AC 417 ms
169,180 KB
testcase_03 AC 1,164 ms
169,220 KB
testcase_04 AC 432 ms
169,216 KB
testcase_05 AC 482 ms
169,440 KB
testcase_06 AC 535 ms
169,488 KB
testcase_07 AC 554 ms
169,488 KB
testcase_08 AC 448 ms
169,476 KB
testcase_09 AC 436 ms
169,524 KB
testcase_10 AC 470 ms
169,440 KB
testcase_11 AC 685 ms
169,488 KB
testcase_12 AC 576 ms
169,488 KB
testcase_13 AC 514 ms
169,488 KB
testcase_14 AC 474 ms
169,476 KB
testcase_15 AC 545 ms
169,488 KB
testcase_16 AC 589 ms
169,440 KB
testcase_17 AC 418 ms
169,216 KB
testcase_18 AC 423 ms
169,216 KB
testcase_19 AC 428 ms
169,216 KB
testcase_20 AC 431 ms
169,528 KB
testcase_21 AC 434 ms
169,488 KB
testcase_22 AC 422 ms
169,216 KB
testcase_23 AC 427 ms
169,216 KB
testcase_24 AC 431 ms
169,216 KB
testcase_25 AC 493 ms
170,016 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from math import sqrt, ceil


def Sieve(n):
    lst = [True] * (n + 1)
    S = set()
    for i in range(2, ceil(sqrt(n)) + 1):
        if lst[i]:
            for j in range(2 * i, n + 1, i):
                lst[j] = False
    for i in range(2, n + 1):
        if lst[i]:
            S.add(i)
    return lst

N = int(input())
A = set(map(int, input().split()))
M = 5 * 10**6
cnt = 0
Prime = Sieve(M)
S = set()
ans = -1
flag = 0 
Prime[1] = 0
for i in range(1, M + 1):
    if Prime[i]:
        for p in str(i):
            if int(p) not in A:
                S = set()
                cnt, flag = 0, 0
                break
        else:
            cnt += 1
            for p in str(i):
                S.add(int(p))
    else:
        cnt += 1
    
    if S == A:
        flag = 1
    if flag:
        ans = max(ans, cnt - 1) 

print(ans)
0