結果

問題 No.12 限定された素数
ユーザー pluto77pluto77
提出日時 2017-04-13 16:02:03
言語 Python2
(2.7.18)
結果
AC  
実行時間 1,567 ms / 5,000 ms
コード長 579 bytes
コンパイル時間 240 ms
コンパイル使用メモリ 6,644 KB
実行使用メモリ 91,320 KB
最終ジャッジ日時 2023-08-15 23:38:38
合計ジャッジ時間 37,102 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1,281 ms
91,272 KB
testcase_01 AC 1,272 ms
91,116 KB
testcase_02 AC 1,288 ms
91,196 KB
testcase_03 AC 1,567 ms
91,124 KB
testcase_04 AC 1,270 ms
91,196 KB
testcase_05 AC 1,290 ms
91,320 KB
testcase_06 AC 1,339 ms
91,136 KB
testcase_07 AC 1,391 ms
91,192 KB
testcase_08 AC 1,291 ms
91,132 KB
testcase_09 AC 1,275 ms
91,196 KB
testcase_10 AC 1,280 ms
91,244 KB
testcase_11 AC 1,481 ms
91,052 KB
testcase_12 AC 1,373 ms
91,192 KB
testcase_13 AC 1,317 ms
91,112 KB
testcase_14 AC 1,274 ms
91,320 KB
testcase_15 AC 1,301 ms
91,072 KB
testcase_16 AC 1,413 ms
91,136 KB
testcase_17 AC 1,271 ms
91,136 KB
testcase_18 AC 1,275 ms
91,056 KB
testcase_19 AC 1,288 ms
91,188 KB
testcase_20 AC 1,277 ms
91,308 KB
testcase_21 AC 1,267 ms
91,056 KB
testcase_22 AC 1,271 ms
91,208 KB
testcase_23 AC 1,270 ms
91,312 KB
testcase_24 AC 1,271 ms
91,244 KB
testcase_25 AC 1,271 ms
91,256 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#yuki_12

def primes(n): 
 if n==2: return [2]
 elif n<2: return []
 s=range(3,n+1,2)
 mroot = n ** 0.5
 half=(n+1)/2-1
 i=0
 m=3
 while m <= mroot:
  if s[i]:
   j=(m*m-3)/2
   s[j]=0
   while j<half:
    s[j]=0
    j+=m
  i=i+1
  m=2*i+3
 return [2]+[x for x in s if x]

raw_input()
a=set(raw_input().split())
res=-1
l=1
cnt=0
s=set()
for i in primes(5000000):
 ts=set(str(i))
 if len(ts-a)>0:
  if cnt>0 and len(s)==len(a):
   res=max(res,i-1-l)
  l=i+1
  cnt=0
  s=set()
 else:
  s=s.union(set(str(i)))
  cnt+=1
if cnt>0 and len(s)==len(a):
 res=max(res,5000000-l)
print res
0