結果

問題 No.12 限定された素数
ユーザー aaaaaaaaaa2230aaaaaaaaaa2230
提出日時 2021-12-30 23:56:52
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 762 bytes
コンパイル時間 315 ms
コンパイル使用メモリ 82,816 KB
実行使用メモリ 137,896 KB
最終ジャッジ日時 2024-04-16 10:01:56
合計ジャッジ時間 15,550 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 534 ms
137,600 KB
testcase_01 AC 541 ms
137,216 KB
testcase_02 AC 522 ms
137,344 KB
testcase_03 WA -
testcase_04 AC 525 ms
137,564 KB
testcase_05 AC 548 ms
137,524 KB
testcase_06 AC 522 ms
137,568 KB
testcase_07 AC 529 ms
137,472 KB
testcase_08 AC 542 ms
137,600 KB
testcase_09 AC 524 ms
137,344 KB
testcase_10 AC 541 ms
137,728 KB
testcase_11 AC 532 ms
137,384 KB
testcase_12 AC 544 ms
137,216 KB
testcase_13 AC 528 ms
137,548 KB
testcase_14 AC 549 ms
137,896 KB
testcase_15 AC 529 ms
137,384 KB
testcase_16 AC 541 ms
137,588 KB
testcase_17 AC 537 ms
137,728 KB
testcase_18 AC 516 ms
137,216 KB
testcase_19 AC 510 ms
137,472 KB
testcase_20 AC 525 ms
137,600 KB
testcase_21 AC 525 ms
137,600 KB
testcase_22 AC 520 ms
137,472 KB
testcase_23 AC 525 ms
137,472 KB
testcase_24 AC 514 ms
137,344 KB
testcase_25 AC 556 ms
137,344 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

R = 5000000

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