結果

問題 No.12 限定された素数
ユーザー takakintakakin
提出日時 2020-06-08 22:35:48
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 732 bytes
コンパイル時間 90 ms
コンパイル使用メモリ 10,932 KB
実行使用メモリ 61,328 KB
最終ジャッジ日時 2023-08-27 05:44:23
合計ジャッジ時間 46,531 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1,349 ms
61,120 KB
testcase_01 AC 1,684 ms
61,160 KB
testcase_02 WA -
testcase_03 AC 2,658 ms
61,188 KB
testcase_04 AC 1,466 ms
61,088 KB
testcase_05 AC 1,777 ms
61,132 KB
testcase_06 AC 1,765 ms
61,112 KB
testcase_07 AC 2,101 ms
61,092 KB
testcase_08 AC 1,578 ms
61,188 KB
testcase_09 AC 1,497 ms
61,116 KB
testcase_10 AC 1,761 ms
61,104 KB
testcase_11 AC 2,352 ms
61,228 KB
testcase_12 AC 2,079 ms
61,196 KB
testcase_13 AC 1,822 ms
61,112 KB
testcase_14 AC 1,672 ms
61,092 KB
testcase_15 AC 1,783 ms
61,232 KB
testcase_16 AC 2,286 ms
61,060 KB
testcase_17 WA -
testcase_18 AC 1,379 ms
61,092 KB
testcase_19 AC 1,380 ms
61,116 KB
testcase_20 AC 1,335 ms
61,192 KB
testcase_21 AC 1,435 ms
61,056 KB
testcase_22 AC 1,392 ms
61,084 KB
testcase_23 AC 1,391 ms
61,112 KB
testcase_24 AC 1,340 ms
61,192 KB
testcase_25 AC 1,757 ms
61,088 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input=lambda: sys.stdin.readline().rstrip()
n=int(input())
A=set(int(i) for i in input().split())
def primes(n):
  is_prime=[True]*(n+1)
  is_prime[0]=False
  is_prime[1]=False
  for i in range(2,int(n**0.5)+1):
    if not is_prime[i]:
      continue
    for j in range(i*2,n+1,i):
      is_prime[j]=False
  return [i for i in range(n+1) if is_prime[i]]
P=primes(5*10**6)
cur=set()
prev=1
ans=0
for i,p in enumerate(P):
  cur2=set()
  chk=True
  for pp in str(p):
    if int(pp) in A:
      cur2.add(int(pp))
    else:
      chk=False
      break
  if chk:
    for c in cur2:
      cur.add(c)
  else:
    if A==cur:
      ans=max(ans,p-prev-1)
    cur=set()
    prev=p+1
if A==cur:
  ans=max(ans,5*10**6-prev)
print(ans)
0