結果

問題 No.7 プライムナンバーゲーム
ユーザー DadarithmDadarithm
提出日時 2015-10-04 22:04:43
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 542 ms / 5,000 ms
コード長 549 bytes
コンパイル時間 518 ms
コンパイル使用メモリ 60,876 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-04-09 03:51:27
合計ジャッジ時間 2,245 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,820 KB
testcase_01 AC 2 ms
6,944 KB
testcase_02 AC 1 ms
6,948 KB
testcase_03 AC 2 ms
6,944 KB
testcase_04 AC 2 ms
6,944 KB
testcase_05 AC 2 ms
6,948 KB
testcase_06 AC 2 ms
6,944 KB
testcase_07 AC 2 ms
6,948 KB
testcase_08 AC 2 ms
6,944 KB
testcase_09 AC 5 ms
6,948 KB
testcase_10 AC 1 ms
6,944 KB
testcase_11 AC 2 ms
6,944 KB
testcase_12 AC 542 ms
6,944 KB
testcase_13 AC 1 ms
6,948 KB
testcase_14 AC 8 ms
6,944 KB
testcase_15 AC 7 ms
6,944 KB
testcase_16 AC 353 ms
6,948 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <cmath>
using namespace std;

bool prime(int n)
{
	if (n < 2)
		return false;

	for (int i = 2; i <= sqrt(n); ++i)
	{
		if (n % i == 0)
			return false;
	}
	return true;
}

bool dfs(int n, bool f, int counter)
{
	if (n < 4) return counter % 2 == 0 ? f : !f;

	int flag = false;
	for (int i = 2; 1 < n - i; ++i)
	{
		if (prime(n - i))
		{
			if (!dfs(i, !f, counter + 1))
				return true;
		}
	}

	return false;
}

int main()
{
	int res;
	cin >> res;

	cout << (dfs(res, false, 0) ? "Win" : "Lose") << endl;

	return 0;
}
0