結果

問題 No.12 限定された素数
ユーザー convexineqconvexineq
提出日時 2021-01-05 10:13:40
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 381 ms / 5,000 ms
コード長 1,004 bytes
コンパイル時間 231 ms
コンパイル使用メモリ 82,432 KB
実行使用メモリ 142,332 KB
最終ジャッジ日時 2024-04-23 16:31:47
合計ジャッジ時間 10,209 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 381 ms
141,852 KB
testcase_01 AC 342 ms
141,864 KB
testcase_02 AC 337 ms
142,332 KB
testcase_03 AC 344 ms
142,092 KB
testcase_04 AC 341 ms
141,956 KB
testcase_05 AC 343 ms
141,912 KB
testcase_06 AC 338 ms
142,120 KB
testcase_07 AC 338 ms
142,192 KB
testcase_08 AC 343 ms
142,128 KB
testcase_09 AC 346 ms
141,940 KB
testcase_10 AC 338 ms
142,040 KB
testcase_11 AC 338 ms
142,028 KB
testcase_12 AC 345 ms
141,860 KB
testcase_13 AC 348 ms
141,796 KB
testcase_14 AC 348 ms
142,176 KB
testcase_15 AC 339 ms
142,048 KB
testcase_16 AC 346 ms
141,976 KB
testcase_17 AC 335 ms
141,984 KB
testcase_18 AC 334 ms
142,000 KB
testcase_19 AC 336 ms
141,916 KB
testcase_20 AC 345 ms
141,868 KB
testcase_21 AC 342 ms
142,144 KB
testcase_22 AC 333 ms
142,020 KB
testcase_23 AC 335 ms
141,996 KB
testcase_24 AC 334 ms
141,956 KB
testcase_25 AC 340 ms
142,200 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