結果

問題 No.458 異なる素数の和
ユーザー koyumeishikoyumeishi
提出日時 2016-12-09 02:04:38
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 845 bytes
コンパイル時間 246 ms
コンパイル使用メモリ 30,464 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-05-06 10:10:38
合計ジャッジ時間 2,883 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <cstdio>
#include <cassert>
using namespace std;

template<int N> struct unko{
    int p[N];
    int q[N];
    constexpr unko() : p(), q(){
      for(int i=2; i<N; i++) p[i] = true;
      for(long long i=2; i*i<N; i++){
        if(!p[i]) continue;
        for(long long j=i*i; j<N; j+=i){
          p[j] = false;
        }
      }
      int tail=0;
      for(int i=2; i<N; i++){
        if(p[i]) p[tail++] = i;
      }

      for(int i=1; i<N; i++) q[i] = -1;
      q[0] = 0;
      for(int i=0; i<tail; i++){
        for(int j=N-1-p[i]; j>=0; j--){
          if(q[j] == -1) continue;
          if(q[j+p[i]] < q[j]+1) q[j+p[i]] = q[j]+1;
        }
      }
    }
};



int main(){
  constexpr int sz = 201;
  constexpr auto p = unko<sz>();
  int n;
  scanf("%d", &n);
  if(n<sz) printf("%d\n", p.q[n]);
  else assert(false);
  return 0;
}
0