結果

問題 No.458 異なる素数の和
ユーザー jensenjensen
提出日時 2021-01-15 13:50:40
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 973 bytes
コンパイル時間 267 ms
コンパイル使用メモリ 11,032 KB
実行使用メモリ 363,888 KB
最終ジャッジ日時 2023-08-17 03:56:58
合計ジャッジ時間 11,737 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 21 ms
8,184 KB
testcase_01 AC 504 ms
109,684 KB
testcase_02 AC 696 ms
140,984 KB
testcase_03 AC 151 ms
30,692 KB
testcase_04 AC 179 ms
37,444 KB
testcase_05 AC 1,424 ms
304,288 KB
testcase_06 AC 657 ms
133,468 KB
testcase_07 AC 24 ms
8,888 KB
testcase_08 AC 1,442 ms
306,800 KB
testcase_09 AC 62 ms
15,124 KB
testcase_10 AC 17 ms
8,104 KB
testcase_11 AC 1,755 ms
363,888 KB
testcase_12 AC 17 ms
8,060 KB
testcase_13 WA -
testcase_14 AC 17 ms
8,088 KB
testcase_15 WA -
testcase_16 AC 102 ms
21,172 KB
testcase_17 AC 18 ms
8,080 KB
testcase_18 AC 17 ms
8,064 KB
testcase_19 AC 17 ms
8,056 KB
testcase_20 AC 18 ms
8,060 KB
testcase_21 AC 18 ms
8,132 KB
testcase_22 AC 17 ms
8,200 KB
testcase_23 AC 18 ms
8,180 KB
testcase_24 AC 18 ms
8,188 KB
testcase_25 AC 17 ms
8,140 KB
testcase_26 AC 18 ms
8,140 KB
testcase_27 AC 628 ms
127,216 KB
testcase_28 AC 1,713 ms
356,248 KB
testcase_29 AC 42 ms
11,472 KB
testcase_30 AC 374 ms
81,512 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import math

def is_prime(n):
    if n == 1: return False

    for k in range(2, int(math.sqrt(n)) + 1):
        if n % k == 0:
            return False

    return True
def find(l,iter,a):
    for i in range(iter,len(l)):
        if(l[i]>=a):
            break
    return i
            
        
n=int(input())
pris=[]
prisum=[]

for i in range(2,n+1):
    if(is_prime(i)==True):
        pris.append(i)
suum=0

for i in range(0,len(pris)):
    suum+=pris[i]
    prisum.append(suum)
x=len(pris)


f=[[0]*x for i in range(n)]
if(n==1):
    print(-1)
elif(n==2):
    print(1)
elif(n>4):
    f[1][0]=1
    f[2][1]=1
    ite=0
    for i in range(4,n):
        ite=find(prisum,ite,i+1)
        for j in range(ite,min(ite+5,x)):
            if(i+1==pris[j]):
                f[i][j]=1
            else:
                z=max(f[i-pris[j]][:j])
                if(z>0):
                    f[i][j]=z+1
    mv=max(f[n-1])
    if(mv==0):
        print(-1)
    else:
        print(mv)
0