結果

問題 No.12 限定された素数
ユーザー zimphazimpha
提出日時 2017-12-07 14:23:04
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 437 ms / 5,000 ms
コード長 529 bytes
コンパイル時間 474 ms
コンパイル使用メモリ 86,988 KB
実行使用メモリ 136,280 KB
最終ジャッジ日時 2023-08-16 00:43:17
合計ジャッジ時間 12,619 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 421 ms
135,680 KB
testcase_01 AC 437 ms
135,920 KB
testcase_02 AC 417 ms
135,888 KB
testcase_03 AC 418 ms
135,760 KB
testcase_04 AC 400 ms
135,932 KB
testcase_05 AC 413 ms
136,088 KB
testcase_06 AC 404 ms
136,148 KB
testcase_07 AC 420 ms
135,988 KB
testcase_08 AC 407 ms
135,756 KB
testcase_09 AC 415 ms
136,132 KB
testcase_10 AC 415 ms
136,280 KB
testcase_11 AC 410 ms
135,968 KB
testcase_12 AC 426 ms
136,184 KB
testcase_13 AC 415 ms
135,876 KB
testcase_14 AC 422 ms
136,224 KB
testcase_15 AC 402 ms
135,952 KB
testcase_16 AC 397 ms
135,976 KB
testcase_17 AC 413 ms
135,808 KB
testcase_18 AC 402 ms
135,916 KB
testcase_19 AC 409 ms
135,680 KB
testcase_20 AC 403 ms
135,792 KB
testcase_21 AC 423 ms
135,928 KB
testcase_22 AC 411 ms
136,164 KB
testcase_23 AC 427 ms
135,804 KB
testcase_24 AC 423 ms
135,700 KB
testcase_25 AC 408 ms
136,268 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def init_primes(n):
  mark = [0] * (n + 1)
  ps = []
  for i in range(2, n + 1):
    if not mark[i]: ps.append(i)
    for p in ps:
      if p * i > n: break
      mark[p * i] = 1
      if i % p == 0: break
  return ps

input()
ds = set(input().split())
s = set()
ret, last = -1, 1
n = 5000000

for p in init_primes(n):
  t = set(str(p))
  if len(t - ds) > 0:
    if len(ds) == len(s):
      ret = max(ret, p - 1 - last)
    s = set()
    last = p + 1
  else:
    s |= t
if len(ds) == len(s):
  ret = max(ret, n - last)
print(ret)
0