結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,820 KB
testcase_01 AC 2 ms
6,948 KB
testcase_02 AC 1 ms
6,944 KB
testcase_03 AC 2 ms
6,944 KB
testcase_04 AC 2 ms
6,944 KB
testcase_05 AC 2 ms
6,944 KB
testcase_06 AC 2 ms
6,948 KB
testcase_07 AC 1 ms
6,948 KB
testcase_08 AC 1 ms
6,948 KB
testcase_09 AC 5 ms
6,944 KB
testcase_10 AC 1 ms
6,948 KB
testcase_11 AC 2 ms
6,944 KB
testcase_12 AC 564 ms
6,944 KB
testcase_13 AC 1 ms
6,948 KB
testcase_14 AC 8 ms
6,948 KB
testcase_15 AC 7 ms
6,944 KB
testcase_16 AC 367 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)
{
	if (n < 4) return f ? !f : f;

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

	return false;
}

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

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

	return 0;
}
0