結果

問題 No.458 異なる素数の和
ユーザー simansiman
提出日時 2021-05-18 17:43:07
言語 C++17(clang)
(17.0.6 + boost 1.83.0)
結果
AC  
実行時間 23 ms / 2,000 ms
コード長 1,395 bytes
コンパイル時間 1,160 ms
コンパイル使用メモリ 144,960 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-17 06:39:39
合計ジャッジ時間 2,452 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <cassert>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <limits.h>
#include <map>
#include <queue>
#include <string.h>
#include <vector>

using namespace std;
typedef long long ll;

class Prime {
public:
  vector<ll> prime_list;
  const ll MAX_N = 100000;

  Prime() {
    bool checked[MAX_N + 1];
    memset(checked, false, sizeof(checked));

    for (ll i = 2; i <= MAX_N; ++i) {
      if (!checked[i]) {
        prime_list.push_back(i);

        for (ll j = i * i; j <= MAX_N; j += i) {
          checked[j] = true;
        }
      }
    }
  }

  map<ll, int> prime_division(ll n) {
    map<ll, int> res;

    for (ll i = 0; prime_list[i] <= sqrt(n); ++i) {
      ll p = prime_list[i];

      while (n % p == 0) {
        ++res[p];
        n /= p;
      }
    }

    if (n != 1) {
      res[n] = 1;
    }

    return res;
  }

  bool is_prime(ll n) {
    if (n <= 1) return false;

    for (int i = 0; i < prime_list.size(); ++i) {
      if (n % prime_list[i]) return false;
    }

    return true;
  }
};

int main() {
  int N;
  Prime prime;
  cin >> N;
  int dp[N + 1];
  memset(dp, -1, sizeof(dp));
  dp[0] = 0;

  for (ll v : prime.prime_list) {
    if (v > N) break;

    for (int i = N - v; i >= 0; --i) {
      if (dp[i] == -1) continue;

      dp[i + v] = max(dp[i + v], dp[i] + 1);
    }
  }

  cout << dp[N] << endl;

  return 0;
}
0