結果

問題 No.12 限定された素数
ユーザー convexineqconvexineq
提出日時 2021-01-05 10:13:40
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 370 ms / 5,000 ms
コード長 1,004 bytes
コンパイル時間 275 ms
コンパイル使用メモリ 87,256 KB
実行使用メモリ 143,388 KB
最終ジャッジ日時 2023-08-05 19:56:10
合計ジャッジ時間 11,795 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 369 ms
143,388 KB
testcase_01 AC 361 ms
143,388 KB
testcase_02 AC 357 ms
143,328 KB
testcase_03 AC 363 ms
143,216 KB
testcase_04 AC 355 ms
143,232 KB
testcase_05 AC 368 ms
143,292 KB
testcase_06 AC 360 ms
143,020 KB
testcase_07 AC 362 ms
143,204 KB
testcase_08 AC 370 ms
143,044 KB
testcase_09 AC 360 ms
143,244 KB
testcase_10 AC 365 ms
143,324 KB
testcase_11 AC 368 ms
143,136 KB
testcase_12 AC 364 ms
142,960 KB
testcase_13 AC 364 ms
143,072 KB
testcase_14 AC 365 ms
143,140 KB
testcase_15 AC 362 ms
143,080 KB
testcase_16 AC 358 ms
143,256 KB
testcase_17 AC 354 ms
143,200 KB
testcase_18 AC 360 ms
143,148 KB
testcase_19 AC 352 ms
143,084 KB
testcase_20 AC 358 ms
143,016 KB
testcase_21 AC 366 ms
143,268 KB
testcase_22 AC 363 ms
143,140 KB
testcase_23 AC 362 ms
143,076 KB
testcase_24 AC 357 ms
143,288 KB
testcase_25 AC 361 ms
143,152 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def Eratosthenes(N): #N以下の素数のリストを返す
    N+=1
    is_prime_list = [True]*N
    is_prime_list[0], is_prime_list[1] = False, False #リストが必要なときはこの2行を有効化
    for j in range(4,N,2): is_prime_list[j] = False
    m = int(N**0.5)+1
    for i in range(3,m,2):
        if is_prime_list[i]:
            is_prime_list[i*i::2*i]=[False]*((N-i*i-1)//(2*i)+1)
    #return [2] + [i for i in range(3,N,2) if is_prime_list[i]]
    return is_prime_list

def getmask(r):
    v = 0
    while r:
        v |= 1<<(r%10)
        r //= 10
    return v

n = int(input())
*a, = map(int,input().split())
MASK = 0
for ai in a:
    MASK |= 1<<ai

ans = -1
N = 5*10**6+1
lst = Eratosthenes(N)
l = r = 1
while l < N:
    res = 0
    r = l
    while r < N:
        if lst[r]:
            mr = getmask(r)
            if mr&~MASK:
                break
            else:
                res |= mr
        r += 1
    if res == MASK:
        ans = max(ans,r-l-1)
    l = r+1
print(ans)
0