結果

問題 No.12 限定された素数
ユーザー convexineqconvexineq
提出日時 2021-01-05 09:42:21
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,311 bytes
コンパイル時間 301 ms
コンパイル使用メモリ 87,144 KB
実行使用メモリ 143,608 KB
最終ジャッジ日時 2023-08-05 19:23:04
合計ジャッジ時間 40,955 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1,431 ms
143,608 KB
testcase_01 AC 1,484 ms
143,176 KB
testcase_02 AC 1,337 ms
143,524 KB
testcase_03 WA -
testcase_04 AC 1,350 ms
143,252 KB
testcase_05 AC 1,397 ms
143,504 KB
testcase_06 AC 1,375 ms
143,552 KB
testcase_07 AC 1,681 ms
143,352 KB
testcase_08 AC 1,401 ms
143,436 KB
testcase_09 AC 1,420 ms
143,444 KB
testcase_10 AC 1,497 ms
143,368 KB
testcase_11 AC 1,786 ms
143,364 KB
testcase_12 AC 1,463 ms
143,300 KB
testcase_13 AC 1,431 ms
143,440 KB
testcase_14 AC 1,480 ms
143,172 KB
testcase_15 AC 1,421 ms
143,608 KB
testcase_16 AC 1,411 ms
143,316 KB
testcase_17 AC 1,577 ms
143,060 KB
testcase_18 AC 1,389 ms
143,364 KB
testcase_19 AC 1,376 ms
143,388 KB
testcase_20 AC 1,312 ms
143,180 KB
testcase_21 AC 1,496 ms
143,264 KB
testcase_22 AC 1,394 ms
143,440 KB
testcase_23 AC 1,383 ms
143,496 KB
testcase_24 AC 1,463 ms
143,080 KB
testcase_25 AC 1,490 ms
143,288 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def Eratosthenes(N): #N以下の素数のリストを返す
    N+=1
    is_prime_list = [True]*N
    is_prime_list[0], is_prime_list[1] = False, False #リストが必要なときはこの2行を有効化
    for j in range(4,N,2): is_prime_list[j] = False
    m = int(N**0.5)+1
    for i in range(3,m,2):
        if is_prime_list[i]:
            is_prime_list[i*i::2*i]=[False]*((N-i*i-1)//(2*i)+1)
    #return [2] + [i for i in range(3,N,2) if is_prime_list[i]]
    return is_prime_list


res = [0]*10
n = int(input())
*a, = map(int,input().split())
for ai in a:
    res[ai] += 1

N = 5*10**6+1
ans = -1
lst = Eratosthenes(N)
used = [0]*10
r = 1
for l in range(1,N):
    if r < l:
        for i in str(r+1):
            used[int(i)] += 1
        r += 1
    while r < N:
        if lst[r+1]==1:
            flag = 1
            for i in str(r+1):
                if res[int(i)]==0: flag = 0
            if flag:
                for i in str(r+1):
                    used[int(i)] += 1
            else:
                break
        r += 1
    for i in range(10):
        if (res[i] and used[i]==0) or (res[i]==0 and used[i]): break
    else:
        ans = max(ans,r-l)
        #print(l,r,used)
    #if l <= 20: print(l,r,used)
    if lst[l]:
        for i in str(l):
            used[int(i)] -= 1

print(ans)
0