結果
問題 | No.458 異なる素数の和 |
ユーザー | chineristAC |
提出日時 | 2020-04-06 02:10:27 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 1,129 ms / 2,000 ms |
コード長 | 1,013 bytes |
コンパイル時間 | 1,698 ms |
コンパイル使用メモリ | 86,860 KB |
実行使用メモリ | 430,548 KB |
最終ジャッジ日時 | 2023-09-18 08:58:36 |
合計ジャッジ時間 | 10,708 ms |
ジャッジサーバーID (参考情報) |
judge12 / judge15 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 89 ms
75,900 KB |
testcase_01 | AC | 413 ms
176,084 KB |
testcase_02 | AC | 496 ms
198,124 KB |
testcase_03 | AC | 161 ms
87,868 KB |
testcase_04 | AC | 191 ms
105,600 KB |
testcase_05 | AC | 964 ms
371,084 KB |
testcase_06 | AC | 478 ms
198,292 KB |
testcase_07 | AC | 96 ms
76,060 KB |
testcase_08 | AC | 967 ms
373,692 KB |
testcase_09 | AC | 122 ms
83,064 KB |
testcase_10 | AC | 77 ms
71,152 KB |
testcase_11 | AC | 1,129 ms
430,548 KB |
testcase_12 | AC | 78 ms
70,756 KB |
testcase_13 | AC | 79 ms
71,212 KB |
testcase_14 | AC | 77 ms
70,968 KB |
testcase_15 | AC | 77 ms
70,964 KB |
testcase_16 | AC | 140 ms
87,992 KB |
testcase_17 | AC | 82 ms
75,740 KB |
testcase_18 | AC | 83 ms
75,760 KB |
testcase_19 | AC | 77 ms
71,192 KB |
testcase_20 | AC | 83 ms
75,796 KB |
testcase_21 | AC | 77 ms
71,164 KB |
testcase_22 | AC | 78 ms
71,156 KB |
testcase_23 | AC | 84 ms
75,708 KB |
testcase_24 | AC | 85 ms
75,676 KB |
testcase_25 | AC | 78 ms
70,768 KB |
testcase_26 | AC | 83 ms
75,796 KB |
testcase_27 | AC | 463 ms
195,044 KB |
testcase_28 | AC | 1,114 ms
422,916 KB |
testcase_29 | AC | 108 ms
77,148 KB |
testcase_30 | AC | 328 ms
149,140 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=[[-1 for i in range(0,N+1)] for i in range(0,n)] dp[0][2]=1 for i in range(1,n): for j in range(0,N+1): if j>p[i] and dp[i-1][j-p[i]]!=-1: dp[i][j]=max(dp[i-1][j],1+dp[i-1][j-p[i]]) elif j==p[i]: dp[i][j]=max(1,dp[i-1][j]) else: dp[i][j]=dp[i-1][j] print(dp[n-1][N])