結果

問題 No.12 限定された素数
ユーザー matsu7874matsu7874
提出日時 2015-12-08 23:56:32
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 1,114 bytes
コンパイル時間 481 ms
コンパイル使用メモリ 10,968 KB
実行使用メモリ 69,712 KB
最終ジャッジ日時 2023-10-12 22:18:06
合計ジャッジ時間 66,157 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2,243 ms
68,396 KB
testcase_01 WA -
testcase_02 WA -
testcase_03 RE -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 AC 2,209 ms
68,380 KB
testcase_23 AC 2,243 ms
68,352 KB
testcase_24 WA -
testcase_25 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

def prime_sieve(n):
    is_prime = [True for i in range(n + 1)]
    is_prime[0] = False
    is_prime[1] = False
    for i in range(4, n + 1, 2):
        is_prime[i] = False
    for i in range(3, int(n**0.5 + 1), 2):
        if is_prime[i]:
            for j in range(i * i, n + 1, i):
                is_prime[j] = False
    return [i for i in range(n + 1) if is_prime[i]]


def using_digits(n, base=10):
    digits = []
    while n > 0:
        digits.append(n % base)
        n //= base
    return digits

N = int(input())
A = list(map(int, input().split()))
if A == [2]:
    print(1)

primes = [1] + prime_sieve(5000000) + [5000000]
length_primes = len(primes)

digits = [using_digits(p) for p in primes]
digits_count = [0 for i in range(10)]
max_gap = 0
l = 1
r = 1
while r < length_primes:
    ds = using_digits(primes[r])
    if all(d in A for d in ds):
        for d in ds:
            digits_count[d] += 1
        if all(digits_count[a] > 0 for a in A):
            max_gap = max(max_gap, primes[r + 1] - primes[l - 1] - 3)
    else:
        l = r
        digits_count = [0] * 10
    r += 1
print(max_gap)
0