結果
問題 | No.458 異なる素数の和 |
ユーザー |
|
提出日時 | 2017-09-12 00:35:59 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 49 ms / 2,000 ms |
コード長 | 740 bytes |
コンパイル時間 | 900 ms |
コンパイル使用メモリ | 79,664 KB |
実行使用メモリ | 6,820 KB |
最終ジャッジ日時 | 2024-11-07 15:59:31 |
合計ジャッジ時間 | 2,176 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 28 |
ソースコード
//https://yukicoder.me/problems/no/458 //https://yukicoder.me/submissions/203775 #include <iostream> #include <cstdio> #include <cmath> #include <algorithm> #include <stack> #include <queue> #include <set> #include <vector> #include <string> #include <string.h> using namespace std; const int MAX_N=20000; int n; int dp[MAX_N+1]={}; bool p[MAX_N+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) continue; else p[i]=false; } } memset(dp,-1,sizeof(dp)); dp[0]++; 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; }