結果

問題 No.12 限定された素数
ユーザー dangodango
提出日時 2023-07-08 09:11:36
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 460 ms / 5,000 ms
コード長 900 bytes
コンパイル時間 308 ms
コンパイル使用メモリ 87,004 KB
実行使用メモリ 135,996 KB
最終ジャッジ日時 2023-09-29 10:28:05
合計ジャッジ時間 13,391 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 435 ms
135,688 KB
testcase_01 AC 442 ms
135,788 KB
testcase_02 AC 428 ms
135,732 KB
testcase_03 AC 425 ms
135,688 KB
testcase_04 AC 431 ms
135,740 KB
testcase_05 AC 444 ms
135,908 KB
testcase_06 AC 426 ms
135,804 KB
testcase_07 AC 434 ms
135,760 KB
testcase_08 AC 460 ms
135,984 KB
testcase_09 AC 432 ms
135,872 KB
testcase_10 AC 457 ms
135,976 KB
testcase_11 AC 439 ms
135,912 KB
testcase_12 AC 433 ms
135,888 KB
testcase_13 AC 418 ms
135,768 KB
testcase_14 AC 436 ms
135,820 KB
testcase_15 AC 432 ms
135,776 KB
testcase_16 AC 444 ms
135,596 KB
testcase_17 AC 431 ms
135,644 KB
testcase_18 AC 437 ms
135,604 KB
testcase_19 AC 436 ms
135,740 KB
testcase_20 AC 429 ms
135,996 KB
testcase_21 AC 438 ms
135,872 KB
testcase_22 AC 431 ms
135,740 KB
testcase_23 AC 429 ms
135,736 KB
testcase_24 AC 435 ms
135,512 KB
testcase_25 AC 451 ms
135,632 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def generate_primes(limit):
    is_prime = [0] * (limit + 1)
    primes = []
    for i in range(2, limit + 1):
        if not is_prime[i]:
            primes.append(i)
        for prime in primes:
            if prime * i > limit:
                break
            is_prime[prime * i] = 1
            if i % prime == 0:
                break
    return primes
input()
digits = set(input().split())
current_digits = set()
max_length, last_prime = -1, 1
for prime in generate_primes(5000000):
    prime_digits = set(str(prime))
    if len(prime_digits - digits) > 0:
        if len(digits) == len(current_digits):
            max_length = max(max_length, prime - 1 - last_prime)
        current_digits = set()
        last_prime = prime + 1
    else:
        current_digits |= prime_digits
if len(digits) == len(current_digits):
    max_length = max(max_length, 5000000 - last_prime)
print(max_length)
0