結果

問題 No.458 異なる素数の和
ユーザー oxyshoweroxyshower
提出日時 2019-02-27 23:51:57
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,430 bytes
コンパイル時間 1,801 ms
コンパイル使用メモリ 178,936 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-05 09:29:33
合計ジャッジ時間 3,445 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
#define int long long

struct Prime{

  vector<int> prime; // 2,3,5,7,11...
  vector<bool> is_prime; // 素数=1,合成数=0
  void eratos(int n){
    is_prime.resize(n+1,true);
    is_prime[0] = is_prime[1] = false;
    for(int i = 2; i <= n; i++){
      if(is_prime[i]){
        prime.push_back(i);
        for(int j = i*2; j <= n; j+=i){
          is_prime[j] = false;
        }
      }
    }
  }

  //因数分解
  map<int,int> prime_factor(int n){
    map<int,int> mp; //{約数,個数}
    for(int i = 2; i*i <= n; i++){
      while(n%i == 0){
        mp[i]++;
        n /= i;
      }
    }
    if(n != 1) mp[n] = 1; //n=素数
    return mp;
  }

  //mpから作れる、約数をちょうどn個もつ数の個数
  int factor_cnt(map<int,int> mp,int n){
    vector<int> dp(n+2); //約数がちょうどi個の数の個数
    dp[1] = 1;
    for(auto p : mp) {
      for(int i = n; i > 0; i--) {
        for(int j = p.second; j > 0; j--) {
          dp[ min(n+1,i*(j+1)) ] += dp[i];
        }
      }
    }
    return dp[n];
  }

}prime;

signed main(){
  cin.tie(0);
  ios::sync_with_stdio(false);

  int n; cin >> n;

  prime.eratos(n);
  vector<int> dp(n+1,0);
  for(int i : prime.prime){
    for(int j = n; j >= 0; j--){
      if(i+j <= n)
        dp[i+j] = max(dp[i+j],dp[j]+1);
    }
  }
  if(dp[n] == 0) cout << -1 << endl;
  else cout << dp[n] << endl;

  return 0;
}
0