結果

問題 No.7 プライムナンバーゲーム
ユーザー dgd1724dgd1724
提出日時 2016-12-01 07:07:01
言語 C++11
(gcc 11.4.0)
結果
TLE  
実行時間 -
コード長 1,770 bytes
コンパイル時間 2,229 ms
コンパイル使用メモリ 152,856 KB
実行使用メモリ 24,808 KB
最終ジャッジ日時 2023-08-18 10:56:02
合計ジャッジ時間 7,957 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,376 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 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

//const static double	de_PI	= 3.14159265358979323846;
//const static double	de_EPS	= 0.000001;
//const static int	de_MOD = 1000000007;
//const static int	de_MAX = 999999999;
//const static int	de_MIN = -999999999;

inline void Enumerate_PrimeNumber(const int &N, std::vector<int> &result) {

	std::vector<bool> flg(N + 1, true);
	for (int i = 2; i*i <= N; i++) {
		if (flg[i]) {
			for (int j = i + i; j <= N; j += i) {
				flg[j] = false;
			}
		}
	}
	for (int i = 2; i < N + 1; i++) {
		if (flg[i]) { result.push_back(i); }
	}

}

inline bool Judge_PrimeNumber(const int &a) {

	if (a < 2) { return false; }
	if (a == 2 || a == 3) { return true; }
	if (a % 2 == 0) { return false; }
	if (a % 6 != 1 && a % 6 != 5) { return false; }

	for (int i = 5; i <= a / i; i += 2) {
		if (a%i == 0) { return false; }
	}

	return true;
}

int main(void) {

	//std::ifstream inf("123.txt");	std::cin.rdbuf(inf.rdbuf());

	int N = 0;
	std::cin >> N;
	std::vector<int> pn;
	Enumerate_PrimeNumber(N, pn);

	bool flg = true;
	std::vector<int> now, next;
	now.push_back(N);
	

	while (1) {
		for (unsigned int j = 0; j < now.size(); j++) {
			int temp = now[j];
			for (unsigned int i = 0; i < pn.size() && pn[i] <= temp; i++) {
				int a = temp - pn[i];
				if (a > 1) {
					if (!Judge_PrimeNumber(a - 2)) {
						if (!Judge_PrimeNumber(a - 3)) {
							next.push_back(a);
						}
					}
				}
			}
		}
		if (next.empty()) { break; }
		std::sort(next.begin(), next.end());
		next.erase(std::unique(next.begin(), next.end()), next.end());
		
		now.clear();
		std::copy(next.begin(), next.end(), std::back_inserter(now));
		next.clear();
		flg = !flg;
		
	}

	if (flg) {
		std::cout << "Lose" << std::endl;
	}
	else {
		std::cout << "Win" << std::endl;
	}

}

0