結果

問題 No.458 異なる素数の和
ユーザー olpheolphe
提出日時 2016-12-09 09:17:20
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 927 bytes
コンパイル時間 739 ms
コンパイル使用メモリ 82,724 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-05-06 10:17:25
合計ジャッジ時間 1,659 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include "iostream"
#include "time.h"
#include "stdlib.h"
#include "iomanip"
#include "math.h"
#include "algorithm"
#include "functional"
#include "list"

using namespace std;

int n;
list<int>p;
bool flag;
int ans;
int sum;

int main() {
	cin >> n;
	p.push_back(2);
	for (int i = 3; i <= n; i++) {
		flag = true;
		for (auto j = p.begin(); (*j)*(*j) <= i; ++j) {
			if (i % (*j)==0) {
				flag = false;
				break;
			}
		}
		if (flag)p.push_back(i);
	}
	for (auto i = p.begin(); sum<n; ++i) {
		//cout << (*i) << "\n";
		sum += (*i);
		ans++;
	}
	//cout << sum << "\n";
	for (auto i = p.begin(); (*i) <= sum - n; ++i) {
		if ((*i) == sum - n) {
			cout << ans - 1 << "\n";
			return 0;
		}
	}
	if (n == 1) {
		cout << "1\n";
		return 0;
	}
	if (sum - n > 0) {
		if ((sum - n) % 2 == 0)ans -= 2;
		else ans --;
	}
	if (n == 6||n==4)ans = -1;
	if (ans <= 0) {
		cout << "-1\n";
		return 0;
	}
	cout << ans << "\n";
	return 0;
}
0