結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 340 ms
141,952 KB
testcase_01 AC 340 ms
141,876 KB
testcase_02 WA -
testcase_03 AC 336 ms
142,032 KB
testcase_04 AC 342 ms
142,060 KB
testcase_05 AC 350 ms
142,196 KB
testcase_06 AC 346 ms
141,788 KB
testcase_07 AC 346 ms
141,920 KB
testcase_08 AC 339 ms
141,984 KB
testcase_09 AC 347 ms
141,908 KB
testcase_10 AC 342 ms
141,704 KB
testcase_11 AC 344 ms
141,804 KB
testcase_12 AC 347 ms
141,852 KB
testcase_13 AC 352 ms
141,912 KB
testcase_14 AC 353 ms
141,916 KB
testcase_15 AC 351 ms
141,972 KB
testcase_16 AC 348 ms
141,924 KB
testcase_17 WA -
testcase_18 AC 328 ms
141,756 KB
testcase_19 AC 330 ms
142,092 KB
testcase_20 AC 336 ms
141,768 KB
testcase_21 AC 337 ms
141,820 KB
testcase_22 AC 338 ms
141,976 KB
testcase_23 AC 339 ms
142,040 KB
testcase_24 AC 341 ms
141,780 KB
testcase_25 AC 336 ms
141,948 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 = 0
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