結果

問題 No.12 限定された素数
ユーザー こるこる
提出日時 2017-01-07 12:04:03
言語 Python3
(3.11.6 + numpy 1.26.0 + scipy 1.11.3)
結果
WA  
実行時間 -
コード長 908 bytes
コンパイル時間 166 ms
コンパイル使用メモリ 10,800 KB
実行使用メモリ 413,796 KB
最終ジャッジ日時 2023-08-22 15:44:45
合計ジャッジ時間 23,435 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3,998 ms
413,796 KB
testcase_01 AC 4,495 ms
206,780 KB
testcase_02 WA -
testcase_03 TLE -
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 #

n=int(input())
a=[str(i)[0] for i in input().split()]
maxi=5000000
e=list(range(maxi+1))
e[1]=0
i=2
while i**2<=maxi:
    j=i+i
    while j<=maxi:
        e[j]=0
        j+=i
    i+=1
    while e[i]==0:
        i+=1
list=[]
for i in e:
    if i!=0: list.append(i)

sum_max=0

def check(num):
    s=str(num)
    for i in range(len(s)):
        if not s[i] in a:
            return False
    return True


l=0
end_list=[0]*n
for r in range(len(list)):
    if check(list[r]):
        for i in range(len(a)):
            for j in range(len(str(list[r]))):
                if a[i]==str(list[r])[j]:
                    end_list[i]=1
        if sum(end_list)==n:
            r_index= maxi if r==len(list)-1 else list[r+1]-1
            l_index= 1 if l==0 else list[l-1]+1
            sum_max=max(sum_max,(r_index-l_index))
    else:
        for i in range(len(end_list)): end_list[i]=0
        l=r+1
print(sum_max)
0