結果

問題 No.12 限定された素数
ユーザー titiatitia
提出日時 2021-11-02 04:23:57
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
実行時間 -
コード長 946 bytes
コンパイル時間 158 ms
コンパイル使用メモリ 12,800 KB
実行使用メモリ 299,136 KB
最終ジャッジ日時 2024-04-19 09:06:51
合計ジャッジ時間 12,948 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 TLE -
testcase_01 -- -
testcase_02 -- -
testcase_03 -- -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

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)
        
    
0