結果

問題 No.12 限定された素数
ユーザー yuki2006yuki2006
提出日時 2015-02-05 02:45:23
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 369 ms / 5,000 ms
コード長 676 bytes
コンパイル時間 270 ms
コンパイル使用メモリ 87,152 KB
実行使用メモリ 124,452 KB
最終ジャッジ日時 2023-09-07 22:43:30
合計ジャッジ時間 10,590 ms
ジャッジサーバーID
(参考情報)
judge4 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 340 ms
124,108 KB
testcase_01 AC 337 ms
124,328 KB
testcase_02 AC 335 ms
124,232 KB
testcase_03 AC 316 ms
124,192 KB
testcase_04 AC 335 ms
124,332 KB
testcase_05 AC 346 ms
124,332 KB
testcase_06 AC 342 ms
124,332 KB
testcase_07 AC 353 ms
124,132 KB
testcase_08 AC 345 ms
124,192 KB
testcase_09 AC 341 ms
124,372 KB
testcase_10 AC 338 ms
124,096 KB
testcase_11 AC 352 ms
124,440 KB
testcase_12 AC 346 ms
124,076 KB
testcase_13 AC 348 ms
124,444 KB
testcase_14 AC 349 ms
124,188 KB
testcase_15 AC 341 ms
124,452 KB
testcase_16 AC 369 ms
124,148 KB
testcase_17 AC 353 ms
124,144 KB
testcase_18 AC 348 ms
124,272 KB
testcase_19 AC 327 ms
124,272 KB
testcase_20 AC 338 ms
124,100 KB
testcase_21 AC 346 ms
124,364 KB
testcase_22 AC 344 ms
124,448 KB
testcase_23 AC 345 ms
124,336 KB
testcase_24 AC 338 ms
124,056 KB
testcase_25 AC 340 ms
124,260 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

# ref http://yukicoder.me/submissions/3957
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