結果
問題 |
No.458 異なる素数の和
|
ユーザー |
|
提出日時 | 2020-03-27 06:11:52 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 65 ms / 2,000 ms |
コード長 | 969 bytes |
コンパイル時間 | 1,364 ms |
コンパイル使用メモリ | 159,896 KB |
実行使用メモリ | 6,820 KB |
最終ジャッジ日時 | 2025-01-02 08:07:30 |
合計ジャッジ時間 | 2,461 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 28 |
ソースコード
#include <bits/stdc++.h> #include <string> #define ft first #define sc second #define pt(sth) cout << sth << "\n" #define chmax(a, b) {if(a<b) a=b;} #define chmin(a, b) {if(a>b) a=b;} #define moC(a, s, b) (a)=((a)s(b)+MOD)%MOD using namespace std; typedef long long ll; typedef pair<ll, ll> PL; static const ll INF=1e18; static const ll MAX=101010; static const ll MOD=1e9+7; /* for(i=0; i<N; i++) cin >> a[i]; */ vector<ll> ps; void eratos(ll N) { ll isp[N+5]; memset(isp, 1, sizeof(isp)); isp[0]=isp[1]=0; ll i, j; for(i=2; i*i<=N; i++) { if(isp[i]==0) continue; for(j=i+i; j<=N; j+=i) isp[j]=0; } for(i=0; i<=N; i++) if(isp[i]) ps.push_back(i); } int main(void) { ll i, j, k; ll N; cin >> N; ll dp[44444]; eratos(N); for(i=0; i<=N; i++) dp[i]=-1; dp[0]=0; for(auto p: ps) { for(i=N-1; i>=0; i--) { if(dp[i]==-1) continue; chmax(dp[i+p], dp[i]+1); } } pt(dp[N]); }