結果

問題 No.458 異なる素数の和
コンテスト
ユーザー eQe
提出日時 2019-01-14 21:06:32
言語 C++11
(gcc 15.2.0 + boost 1.89.0)
コンパイル:
g++-15 -O2 -lm -std=gnu++11 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
CE  
(最新)
AC  
(最初)
実行時間 -
コード長 1,270 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 4,565 ms
コンパイル使用メモリ 103,712 KB
最終ジャッジ日時 2026-03-07 15:57:22
合計ジャッジ時間 7,624 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
コンパイルエラー時のメッセージ・ソースコードは、提出者また管理者しか表示できないようにしております。(リジャッジ後のコンパイルエラーは公開されます)
ただし、clay言語の場合は開発者のデバッグのため、公開されます。

コンパイルメッセージ
g++-15: fatal error: cannot execute 'as': posix_spawnp: Resource temporarily unavailable
compilation terminated.

ソースコード

diff #
raw source code

#include <iostream>
#include <cmath>
#include <string>
#include <algorithm>
#include <set>
#include <vector>
#include <map>
#include <list>
#include <stack>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <queue>
#define mkp make_pair
#define fi first
#define se second
#define pt(num) cout << num << "\n"
#define max(a, b) ((a)>(b) ? (a):(b))
#define min(a, b) ((a)<(b) ? (a):(b))
#define chmax(a, b) (a<b ? a=b : 0)
#define chmin(a, b) (a>b ? a=b : 0)
#define INF 1000000000000000000
#define MOD 1000000007LL
#define MAX 100010
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef map<ll, ll> Map;

vector<ll> primes;

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]) primes.push_back(i);
}

int main(void) {
    ll M;
    cin >> M;
    ll i, j;
    ll dp[20202];
    memset(dp, -1, sizeof(dp));
    
    eratos(M);
    
    dp[0]=0;
    for(i=0; i<primes.size(); i++)
        for(j=M-primes[i]; j>=0; j--)
            if(dp[j]!=-1) dp[j+primes[i]]=max(dp[j+primes[i]], dp[j]+1);
   
    pt(dp[M]);
}

0