結果

問題 No.458 異なる素数の和
ユーザー eQe
提出日時 2020-03-27 06:11:24
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
RE  
実行時間 -
コード長 969 bytes
コンパイル時間 1,423 ms
コンパイル使用メモリ 158,620 KB
実行使用メモリ 6,820 KB
最終ジャッジ日時 2025-01-02 08:07:23
合計ジャッジ時間 3,752 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 21 RE * 7
権限があれば一括ダウンロードができます

ソースコード

diff #

#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[22222];
  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]);
  
  
}


0