結果

問題 No.458 異なる素数の和
ユーザー polylogKpolylogK
提出日時 2017-09-12 00:45:28
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 416 bytes
コンパイル時間 622 ms
コンパイル使用メモリ 64,752 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-25 05:53:25
合計ジャッジ時間 2,342 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 19 ms
5,376 KB
testcase_02 AC 24 ms
5,376 KB
testcase_03 AC 6 ms
5,376 KB
testcase_04 AC 7 ms
5,376 KB
testcase_05 AC 49 ms
5,376 KB
testcase_06 AC 23 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 50 ms
5,376 KB
testcase_09 AC 4 ms
5,376 KB
testcase_10 WA -
testcase_11 AC 60 ms
5,376 KB
testcase_12 WA -
testcase_13 AC 2 ms
5,376 KB
testcase_14 AC 2 ms
5,376 KB
testcase_15 WA -
testcase_16 AC 5 ms
5,376 KB
testcase_17 AC 2 ms
5,376 KB
testcase_18 AC 2 ms
5,376 KB
testcase_19 AC 2 ms
5,376 KB
testcase_20 AC 2 ms
5,376 KB
testcase_21 AC 2 ms
5,376 KB
testcase_22 AC 2 ms
5,376 KB
testcase_23 AC 2 ms
5,376 KB
testcase_24 AC 2 ms
5,376 KB
testcase_25 AC 2 ms
5,376 KB
testcase_26 AC 2 ms
5,376 KB
testcase_27 AC 22 ms
5,376 KB
testcase_28 AC 57 ms
5,376 KB
testcase_29 AC 3 ms
5,376 KB
testcase_30 AC 14 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
using namespace std;
int n,dp[20000+1]={0};
bool p[20000+1];
int main(){
	cin >> n;
	fill(p,p+sizeof(p),true);
	p[0]=false; p[1]=false;
	for(int i=3;i<=n;i++) for(int j=0;j*j<=i;j++) if(p[j]) if(i%j==0) p[i]=false;	
	for(int i=1;i<n;i++) dp[i]=-1;
	for(int i=2;i<=n;i++) if(p[i]) for(int j=n;j>=0;j--) if(j+i<=n && dp[j]!=-1) dp[j+i] = max(dp[j]+1, dp[j+i]);
	cout << dp[n] << endl;
	return 0;
}
0