結果

問題 No.12 限定された素数
ユーザー roarisroaris
提出日時 2022-09-27 17:52:40
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 390 ms / 5,000 ms
コード長 829 bytes
コンパイル時間 1,710 ms
コンパイル使用メモリ 86,900 KB
実行使用メモリ 142,196 KB
最終ジャッジ日時 2023-08-24 03:57:51
合計ジャッジ時間 12,042 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 317 ms
141,708 KB
testcase_01 AC 333 ms
141,856 KB
testcase_02 AC 331 ms
141,596 KB
testcase_03 AC 390 ms
141,604 KB
testcase_04 AC 318 ms
141,892 KB
testcase_05 AC 352 ms
142,076 KB
testcase_06 AC 344 ms
142,088 KB
testcase_07 AC 362 ms
141,808 KB
testcase_08 AC 336 ms
141,960 KB
testcase_09 AC 340 ms
141,972 KB
testcase_10 AC 348 ms
141,928 KB
testcase_11 AC 369 ms
142,196 KB
testcase_12 AC 362 ms
141,860 KB
testcase_13 AC 349 ms
141,860 KB
testcase_14 AC 350 ms
141,824 KB
testcase_15 AC 356 ms
142,096 KB
testcase_16 AC 371 ms
142,008 KB
testcase_17 AC 321 ms
141,656 KB
testcase_18 AC 328 ms
141,848 KB
testcase_19 AC 321 ms
141,804 KB
testcase_20 AC 319 ms
141,804 KB
testcase_21 AC 328 ms
141,792 KB
testcase_22 AC 327 ms
141,836 KB
testcase_23 AC 334 ms
141,916 KB
testcase_24 AC 329 ms
141,780 KB
testcase_25 AC 368 ms
142,124 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def era(n):
    is_prime = [True]*(n+1)
    is_prime[0] = False
    is_prime[1] = False
    
    for i in range(2, int(n**0.5)+1):
        if not is_prime[i]:
            continue
        
        for j in range(2*i, n+1, i):
            is_prime[j] = False
    
    return [p for p in range(n+1) if is_prime[p]]

N = int(input())
A = list(map(int, input().split()))
S = 0

for Ai in A:
    S += 1<<Ai

p = era(5*10**6)
L = 1
now = 0
ans = -1

for pi in p:
    ok = True
    s = str(pi)
    
    for i in range(len(s)):
        if not (S>>int(s[i]))&1:
            ok = False
            break
    
    if not ok:
        if now==S:
            ans = max(ans, pi-1-L)

        L = pi+1
        now = 0
    else:
        for i in range(len(s)):
            now |= 1<<int(s[i])

if now==S:
    ans = max(ans, 5*10**6-L)

print(ans)
0