結果

問題 No.12 限定された素数
ユーザー aaaaaaaaaa2230aaaaaaaaaa2230
提出日時 2021-12-30 23:59:34
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 546 ms / 5,000 ms
コード長 799 bytes
コンパイル時間 623 ms
コンパイル使用メモリ 82,588 KB
実行使用メモリ 137,800 KB
最終ジャッジ日時 2024-04-16 10:06:45
合計ジャッジ時間 14,825 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 515 ms
137,728 KB
testcase_01 AC 516 ms
137,748 KB
testcase_02 AC 503 ms
137,492 KB
testcase_03 AC 41 ms
51,712 KB
testcase_04 AC 518 ms
137,472 KB
testcase_05 AC 522 ms
137,800 KB
testcase_06 AC 529 ms
137,556 KB
testcase_07 AC 524 ms
137,376 KB
testcase_08 AC 531 ms
137,452 KB
testcase_09 AC 519 ms
137,600 KB
testcase_10 AC 538 ms
137,472 KB
testcase_11 AC 521 ms
137,476 KB
testcase_12 AC 541 ms
137,728 KB
testcase_13 AC 533 ms
137,472 KB
testcase_14 AC 537 ms
137,472 KB
testcase_15 AC 533 ms
137,472 KB
testcase_16 AC 542 ms
137,600 KB
testcase_17 AC 518 ms
137,508 KB
testcase_18 AC 520 ms
137,600 KB
testcase_19 AC 526 ms
137,600 KB
testcase_20 AC 526 ms
137,596 KB
testcase_21 AC 523 ms
137,344 KB
testcase_22 AC 515 ms
137,520 KB
testcase_23 AC 521 ms
137,472 KB
testcase_24 AC 514 ms
137,376 KB
testcase_25 AC 546 ms
137,448 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

n = int(input())
A = list(map(int,input().split()))

R = 5000000
if n == 10:
    print(R-1)
    exit()
sieve = [0]*(R+1)
primes = [0]
for i in range(2,R+1):
    if sieve[i]:
        continue
    primes.append(i)
    for j in range(i,R+1,i):
        sieve[j] = 1
flag = 0
for a in A:
    flag |= 1<<a
ans = -1
now = 1
has = 0
count = [0]*10
l = len(primes)
primes.append(R+2)
for i in range(1,l):
    now = max(now,i)
    while now < l and (has | flag) == flag:
        for j in str(primes[now]):
            j = int(j)
            has |= 1<<j
            count[j] += 1
        now += 1
        if has == flag:
            ans = max(ans,primes[now]-primes[i-1]-2)

    for j in str(primes[i]):
        j = int(j)
        count[j] -= 1
        if count[j] == 0:
            has ^= 1<<j
print(ans)
    
0