結果
問題 | No.458 異なる素数の和 |
ユーザー | chineristAC |
提出日時 | 2020-04-06 02:33:42 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 319 ms / 2,000 ms |
コード長 | 890 bytes |
コンパイル時間 | 1,920 ms |
コンパイル使用メモリ | 86,968 KB |
実行使用メモリ | 76,600 KB |
最終ジャッジ日時 | 2023-09-18 09:59:38 |
合計ジャッジ時間 | 6,899 ms |
ジャッジサーバーID (参考情報) |
judge13 / judge14 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 79 ms
74,864 KB |
testcase_01 | AC | 155 ms
76,452 KB |
testcase_02 | AC | 173 ms
76,168 KB |
testcase_03 | AC | 99 ms
76,244 KB |
testcase_04 | AC | 103 ms
76,184 KB |
testcase_05 | AC | 278 ms
76,600 KB |
testcase_06 | AC | 167 ms
75,836 KB |
testcase_07 | AC | 81 ms
76,036 KB |
testcase_08 | AC | 280 ms
76,204 KB |
testcase_09 | AC | 89 ms
76,228 KB |
testcase_10 | AC | 73 ms
71,120 KB |
testcase_11 | AC | 319 ms
76,148 KB |
testcase_12 | AC | 72 ms
70,984 KB |
testcase_13 | AC | 75 ms
71,016 KB |
testcase_14 | AC | 72 ms
71,016 KB |
testcase_15 | AC | 72 ms
71,228 KB |
testcase_16 | AC | 94 ms
76,168 KB |
testcase_17 | AC | 73 ms
70,984 KB |
testcase_18 | AC | 74 ms
71,032 KB |
testcase_19 | AC | 72 ms
71,176 KB |
testcase_20 | AC | 76 ms
75,524 KB |
testcase_21 | AC | 73 ms
70,824 KB |
testcase_22 | AC | 73 ms
70,820 KB |
testcase_23 | AC | 77 ms
75,548 KB |
testcase_24 | AC | 77 ms
75,520 KB |
testcase_25 | AC | 72 ms
70,804 KB |
testcase_26 | AC | 74 ms
70,900 KB |
testcase_27 | AC | 164 ms
75,536 KB |
testcase_28 | AC | 314 ms
76,352 KB |
testcase_29 | AC | 89 ms
76,168 KB |
testcase_30 | AC | 135 ms
76,048 KB |
ソースコード
def get_sieve_of_eratosthenes_new(n): import math if not isinstance(n, int): raise TypeError('n is int type.') if n < 2: raise ValueError('n is more than 2') prime = [] limit = math.sqrt(n) data = [i + 1 for i in range(1, n)] while True: p = data[0] if limit <= p: return prime + data prime.append(p) data = [e for e in data if e % p != 0] N=int(input()) if N==1: print(-1) else: import math if int(math.sqrt(N))**2==N: p=get_sieve_of_eratosthenes_new(N+1) else: p=get_sieve_of_eratosthenes_new(N) n=len(p) dp=[-10**10 for i in range(0,N+1)] dp[N-2]=1 for i in range(1,n): for j in range(0,N-p[i]): dp[j]=max(dp[j],1+dp[j+p[i]]) dp[N-p[i]]=max(1,dp[N-p[i]]) if dp[0]>0: print(dp[0]) else: print(-1)