結果

問題 No.458 異なる素数の和
ユーザー こるこる
提出日時 2017-05-05 23:27:53
言語 C++11
(gcc 11.4.0)
結果
TLE  
実行時間 -
コード長 924 bytes
コンパイル時間 764 ms
コンパイル使用メモリ 70,240 KB
実行使用メモリ 8,712 KB
最終ジャッジ日時 2023-10-12 10:22:12
合計ジャッジ時間 5,168 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include<math.h>
#define rep(i,a) for(int i=0;i<a;i++)
#define nrep(i,a,b) for(int i=a;i<b;i++)
#define mrep(i,a) for(int i=a;i>=0;i--)
#define ll long long
#define INF 11451419191810
using namespace std;

ll n;
vector<ll> p;

void dfs(ll sum, ll index,ll ans){
	if (index == p.size()) return;
	if (sum == n){
		cout << ans << endl;
		exit(0);
	}if (sum > n){
		return ;
	}
	else{
		nrep(i, index, p.size()){
			dfs(sum + p[index], i+1, ans + 1);
		}
	}
}

int main(){

	cin >> n;
	vector<bool> prime(n + 1);
	rep(i, n+1) prime[i] = true;
	prime[0] = false;
	prime[1] = false;
	ll index = 2;
	while (index*index < n){
		if (prime[index]){
			ll j = index + index;
			while (j <= n){
				prime[j] = false;
				j += index;
			}
		}index++;
	}ll count = 0;
	rep(i, n + 1) if (prime[i]) p.push_back(i);
	dfs(0, 0, 0);
	cout << -1 << endl;
	return 0;
}
0