結果

問題 No.12 限定された素数
ユーザー sotanishysotanishy
提出日時 2021-03-16 21:56:37
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 434 ms / 5,000 ms
コード長 776 bytes
コンパイル時間 199 ms
コンパイル使用メモリ 82,176 KB
実行使用メモリ 135,464 KB
最終ジャッジ日時 2024-04-26 04:15:49
合計ジャッジ時間 11,326 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 334 ms
135,416 KB
testcase_01 AC 365 ms
135,352 KB
testcase_02 AC 336 ms
135,160 KB
testcase_03 AC 434 ms
135,148 KB
testcase_04 AC 333 ms
135,144 KB
testcase_05 AC 373 ms
135,156 KB
testcase_06 AC 359 ms
135,228 KB
testcase_07 AC 384 ms
135,348 KB
testcase_08 AC 364 ms
135,224 KB
testcase_09 AC 351 ms
135,360 KB
testcase_10 AC 371 ms
135,276 KB
testcase_11 AC 397 ms
135,032 KB
testcase_12 AC 381 ms
135,180 KB
testcase_13 AC 372 ms
135,248 KB
testcase_14 AC 368 ms
135,096 KB
testcase_15 AC 375 ms
135,188 KB
testcase_16 AC 418 ms
135,144 KB
testcase_17 AC 326 ms
135,116 KB
testcase_18 AC 335 ms
135,292 KB
testcase_19 AC 332 ms
135,412 KB
testcase_20 AC 330 ms
135,344 KB
testcase_21 AC 354 ms
135,464 KB
testcase_22 AC 364 ms
135,036 KB
testcase_23 AC 365 ms
135,140 KB
testcase_24 AC 364 ms
135,096 KB
testcase_25 AC 404 ms
135,148 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def sieve(n):
    is_prime = [True] * (n+1)
    is_prime[0] = is_prime[1] = False
    for j in range(4, n+1, 2):
        is_prime[j] = False
    prime = [2]
    for i in range(3, n+1):
        if is_prime[i]:
            prime.append(i)
            for j in range(i*i, n+1, 2*i):
                is_prime[j] = False
    return prime

M = 5*10**6
prime = [0] + sieve(M) + [M+1]
N = int(input())
A = set(map(int, input().split()))
st = set()
ans = -1
left = 0
for i, p in enumerate(prime):
    if i == 0 or i == len(prime) - 1:
        continue
    for d in map(int, str(p)):
        if d not in A:
            st = set()
            left = i
            break
        st.add(d)
    else:
        if st == A:
            ans = max(ans, prime[i + 1] - prime[left] - 2)
print(ans)
0