結果
問題 | No.458 異なる素数の和 |
ユーザー |
![]() |
提出日時 | 2016-12-28 23:18:19 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 22 ms / 2,000 ms |
コード長 | 432 bytes |
コンパイル時間 | 1,215 ms |
コンパイル使用メモリ | 165,584 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-07-05 05:56:04 |
合計ジャッジ時間 | 2,596 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 28 |
ソースコード
#include<bits/stdc++.h>using namespace std;int A[20001];int memo[20001];int main() {memset(memo, -1, sizeof(memo));memo[0] = 0;for(int i = 2; i <= 20000; ++i){if(!A[i]){for(int j = i * 2; j <= 20000; j += i){A[j] = 1;}for(int j = 20000; j >= i; --j){if(memo[j - i] >= 0){memo[j] = max(memo[j], memo[j - i] + 1);}}}}int n;cin >> n;cout << memo[n] << endl;return 0;}