結果
| 問題 | No.12 限定された素数 |
| コンテスト | |
| ユーザー |
titia
|
| 提出日時 | 2021-11-02 04:24:29 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 2,739 ms / 5,000 ms |
| コード長 | 946 bytes |
| 記録 | |
| コンパイル時間 | 519 ms |
| コンパイル使用メモリ | 82,284 KB |
| 実行使用メモリ | 400,336 KB |
| 最終ジャッジ日時 | 2024-10-11 01:42:26 |
| 合計ジャッジ時間 | 57,984 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 26 |
ソースコード
from collections import Counter
N=int(input())
A=Counter(input().split())
x=5000000
import math
L=math.floor(math.sqrt(x)) # 平方根を求める
Primelist=[i for i in range(x+1)]
Primelist[1]=0 # 1は素数でないので0にする.
for i in Primelist:
if i>L:
break
if i==0:
continue
for j in range(2*i,x+1,i):
Primelist[j]=0
Primes=[0]+[Primelist[j] for j in range(x+1) if Primelist[j]!=0]
P2=[]
for p in Primes:
P2.append(Counter(str(p)))
S=Counter()
ANS=-1
end=1
for now in range(1,len(Primes)):
while set(S)<=set(A):
if set(S)==set(A):
if end==348514:
ANS=max(ANS,5000001-Primes[now-1]-2)
else:
ANS=max(ANS,Primes[end]-Primes[now-1]-2)
if end==348514:
break
S+=P2[end]
end+=1
#print(Primes[now],Primes[end],ANS,A,S)
S-=P2[now]
print(ANS)
titia