結果

問題 No.12 限定された素数
ユーザー maspymaspy
提出日時 2020-03-19 14:06:42
言語 PyPy3
(7.3.13)
結果
AC  
実行時間 272 ms / 5,000 ms
コード長 1,057 bytes
コンパイル時間 706 ms
コンパイル使用メモリ 86,944 KB
実行使用メモリ 139,460 KB
最終ジャッジ日時 2023-08-16 01:15:57
合計ジャッジ時間 9,307 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 265 ms
131,540 KB
testcase_01 AC 272 ms
131,600 KB
testcase_02 AC 264 ms
131,608 KB
testcase_03 AC 238 ms
139,460 KB
testcase_04 AC 218 ms
131,620 KB
testcase_05 AC 221 ms
132,776 KB
testcase_06 AC 246 ms
132,680 KB
testcase_07 AC 249 ms
134,712 KB
testcase_08 AC 228 ms
131,728 KB
testcase_09 AC 219 ms
131,936 KB
testcase_10 AC 224 ms
133,428 KB
testcase_11 AC 245 ms
137,120 KB
testcase_12 AC 235 ms
133,032 KB
testcase_13 AC 229 ms
132,196 KB
testcase_14 AC 231 ms
133,116 KB
testcase_15 AC 226 ms
132,084 KB
testcase_16 AC 242 ms
135,768 KB
testcase_17 AC 221 ms
131,664 KB
testcase_18 AC 231 ms
131,596 KB
testcase_19 AC 237 ms
131,716 KB
testcase_20 AC 239 ms
131,612 KB
testcase_21 AC 221 ms
131,960 KB
testcase_22 AC 211 ms
131,816 KB
testcase_23 AC 220 ms
131,620 KB
testcase_24 AC 218 ms
131,636 KB
testcase_25 AC 231 ms
132,384 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#!/usr/bin/ python3.8
# %%
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines


N = int(readline())
A = map(int, read().split())

full = 0
for x in A:
    full += (1 << x)


def num_to_set(n):
    x = 0
    while n:
        n, r = divmod(n, 10)
        x |= (1 << r)
    return x


U = 5 * 10 ** 6 + 1
is_prime = [0] * U
is_prime[2] = 1
for n in range(3, U, 2):
    is_prime[n] = 1
for p in range(3, U, 2):
    if p * p >= U:
        break
    if is_prime[p]:
        for i in range(p * p, U, p + p):
            is_prime[i] = 0

ng = []
ok = []
for p in range(U):
    if is_prime[p]:
        s = num_to_set(p)
        if s & (~full):
            ng.append(p)
        else:
            ok.append((p, s))

ng.append(U)
ok.append((U, 0))
L = 1
i = 0
answer = -1
for x in ng:
    R = x - 1
    se = 0
    while True:
        p, s = ok[i]
        if p > R:
            break
        se |= s
        i += 1
    if se == full and answer < R - L:
        answer = R - L
    L = x + 1

print(answer)
0