結果

問題 No.12 限定された素数
ユーザー HydruHydru
提出日時 2023-01-20 01:34:36
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,273 ms / 5,000 ms
コード長 889 bytes
コンパイル時間 1,715 ms
コンパイル使用メモリ 87,180 KB
実行使用メモリ 331,032 KB
最終ジャッジ日時 2023-09-04 21:06:59
合計ジャッジ時間 36,088 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1,225 ms
330,912 KB
testcase_01 AC 1,231 ms
330,576 KB
testcase_02 AC 1,269 ms
330,368 KB
testcase_03 AC 1,227 ms
330,828 KB
testcase_04 AC 1,217 ms
330,856 KB
testcase_05 AC 1,247 ms
330,584 KB
testcase_06 AC 1,236 ms
330,628 KB
testcase_07 AC 1,231 ms
330,796 KB
testcase_08 AC 1,242 ms
330,540 KB
testcase_09 AC 1,247 ms
330,624 KB
testcase_10 AC 1,251 ms
330,488 KB
testcase_11 AC 1,251 ms
330,556 KB
testcase_12 AC 1,254 ms
330,652 KB
testcase_13 AC 1,242 ms
330,700 KB
testcase_14 AC 1,273 ms
330,944 KB
testcase_15 AC 1,250 ms
330,548 KB
testcase_16 AC 1,273 ms
330,704 KB
testcase_17 AC 1,256 ms
330,564 KB
testcase_18 AC 1,244 ms
330,936 KB
testcase_19 AC 1,253 ms
330,672 KB
testcase_20 AC 1,261 ms
330,808 KB
testcase_21 AC 1,242 ms
330,356 KB
testcase_22 AC 1,273 ms
331,032 KB
testcase_23 AC 1,258 ms
330,968 KB
testcase_24 AC 1,250 ms
330,568 KB
testcase_25 AC 1,260 ms
330,828 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def eratosthenes(n):
    primes=set(range(2,n+1))
    for i in range(2,n):
        if i in primes:
            it = i ** 2
            while it <= n:
                if it in primes:
                    primes.remove(it)
                it += i
    return primes

P=sorted(list(eratosthenes(5*10**6)))

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

digit = [0 for _ in range(10)]
for a in A:
    digit[a]=1

ans=-1
n_digit = [0 for _ in range(10)]

P.append(5*10**6+1)
k=1
for i in range(len(P)-1):
    p=P[i]
    while(p>0):
        n_digit[p%10]=1
        p//=10
    
    flag=1
    for j in range(10):
        if digit[j]==0 and n_digit[j]==1:
            for l in range(10):
                n_digit[l]=0
            k=P[i]+1
            flag=0
            break
        if digit[j]==1 and n_digit[j]==0:
            flag=0
    if flag==1:
        ans=max(ans,P[i+1]-1-k)

print(ans)
0