結果

問題 No.12 限定された素数
ユーザー takakintakakin
提出日時 2020-06-08 22:36:52
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 2,618 ms / 5,000 ms
コード長 733 bytes
コンパイル時間 162 ms
コンパイル使用メモリ 11,036 KB
実行使用メモリ 61,208 KB
最終ジャッジ日時 2023-08-27 05:46:48
合計ジャッジ時間 46,076 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1,320 ms
61,064 KB
testcase_01 AC 1,672 ms
61,116 KB
testcase_02 AC 1,367 ms
61,152 KB
testcase_03 AC 2,618 ms
61,072 KB
testcase_04 AC 1,416 ms
61,080 KB
testcase_05 AC 1,730 ms
61,060 KB
testcase_06 AC 1,771 ms
61,208 KB
testcase_07 AC 2,073 ms
61,052 KB
testcase_08 AC 1,557 ms
61,096 KB
testcase_09 AC 1,475 ms
61,148 KB
testcase_10 AC 1,726 ms
61,176 KB
testcase_11 AC 2,349 ms
61,080 KB
testcase_12 AC 2,073 ms
61,168 KB
testcase_13 AC 1,779 ms
61,144 KB
testcase_14 AC 1,687 ms
61,144 KB
testcase_15 AC 1,776 ms
61,120 KB
testcase_16 AC 2,298 ms
61,148 KB
testcase_17 AC 1,318 ms
61,072 KB
testcase_18 AC 1,334 ms
61,068 KB
testcase_19 AC 1,355 ms
61,172 KB
testcase_20 AC 1,306 ms
61,136 KB
testcase_21 AC 1,436 ms
61,064 KB
testcase_22 AC 1,358 ms
61,116 KB
testcase_23 AC 1,351 ms
61,156 KB
testcase_24 AC 1,309 ms
61,060 KB
testcase_25 AC 1,759 ms
61,096 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=-1
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