結果

問題 No.458 異なる素数の和
ユーザー naimonon77naimonon77
提出日時 2016-12-28 20:21:05
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,349 bytes
コンパイル時間 1,599 ms
コンパイル使用メモリ 175,872 KB
実行使用メモリ 8,768 KB
最終ジャッジ日時 2023-08-21 18:25:06
合計ジャッジ時間 9,645 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
4,376 KB
testcase_01 AC 1,445 ms
4,380 KB
testcase_02 AC 1,874 ms
4,384 KB
testcase_03 AC 280 ms
4,376 KB
testcase_04 AC 368 ms
4,380 KB
testcase_05 TLE -
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 "bits/stdc++.h"

#define REP(i,a,b) for(int i=a;i<b;++i)
#define rep(i,n) for(int i=0;i<n;++i)
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define ALL(a) begin(a),end(a)
#define ifnot(a) if(not (a))
#define dump(x)  cerr << #x << " = " << (x) << endl
using namespace std;

int dx[] = { 0,1,0,-1 };
int dy[] = { 1,0,-1,0 };
#define INF (1 << 28)
ull mod = (int)1e9 + 7;
//.....................
const int MAX = (int)1e5 + 5;

static int prime[MAX + 5];
static int isprime[MAX + 5];
void eratosthenes(int N) {
	for (int i = 0; i < N; i++) {
		isprime[i] = 1;
	}
	for (int i = 2; i < sqrt((double)N); i++) {
		if (isprime[i]) {
			for (int j = 0; i * (j + 2) < N; j++) {
				isprime[i *(j + 2)] = 0;
			}
		}
	}
	int a = 0;
	for (int i = 2; i < N; i++) {
		if (isprime[i]) {
			prime[a++] = i;
		}
	}
}

int T = 1;
int N;
vector<int> a;

void solve() {
	eratosthenes(MAX);
	cin >> N;
	// rep(i, 100) {
	//      cout << prime[i] << endl;
	// }
	map<int, int> dp;
	dp[0] = 1;
	for (int i = 0; prime[i] <= N; i++) {
		for (int j = N; ; j--) {
			int a = j - prime[i];
			if (a < 0) break;
			if (dp[a] > 0) if (dp[j] < dp[a] + 1) dp[j] = dp[a] + 1;
		}
	}
	if (dp[N] == 1) cout << -1 << endl;
	else cout << dp[N] - 1 << endl;
}

signed main() {
	cout << fixed << setprecision(20);
	rep(i, T) solve();
	return 0;
}
0