結果

問題 No.12 限定された素数
ユーザー gigurururu
提出日時 2014-11-27 21:33:30
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
AC  
実行時間 1,082 ms / 5,000 ms
コード長 664 bytes
コンパイル時間 102 ms
コンパイル使用メモリ 12,672 KB
実行使用メモリ 46,848 KB
最終ジャッジ日時 2024-11-24 07:38:56
合計ジャッジ時間 29,152 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 26
権限があれば一括ダウンロードができます

ソースコード

diff #

import math

def prime(max):
    max2 = (max-3)//2
    sieve = [True]*(max2+1)
    for i in range(int((math.sqrt(max)-3)/2)+1):
        if not sieve[i]: continue
        k = i+i+3
        j = k*(i+1)+i
        while j <= max2:
            sieve[j] = False
            j += k
    sieve = [2]+[i+i+3 for i in range(max2+1) if sieve[i]]
    return sieve


input()
a=set(input().split())

max=5000000
start=1
rest=a
ans=-1
for i in prime(max):
  l=set(str(i))
  if len(l-a):
    if len(rest)==0 and ans<i-1-start: ans=i-1-start
    start=i+1
    rest=a
  else:
    rest=rest-l
if len(rest)==0 and ans<max-start: ans=max-start
print(ans)
0