結果

問題 No.7 プライムナンバーゲーム
ユーザー rodearodea
提出日時 2017-12-08 21:15:52
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 770 bytes
コンパイル時間 663 ms
コンパイル使用メモリ 68,540 KB
実行使用メモリ 7,440 KB
最終ジャッジ日時 2023-08-19 22:38:49
合計ジャッジ時間 7,512 ms
ジャッジサーバーID
(参考情報)
judge12 / judge10
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 TLE -
testcase_04 AC 675 ms
4,384 KB
testcase_05 AC 647 ms
4,384 KB
testcase_06 TLE -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
using namespace std;

int dp[10000], i, j;

int prime(int n)
{
	if (n == 0 || n == 1)
	{
		return dp[n] = 0;
	}

	if (n == 2 || n == 3)
	{
		return dp[n] = 1;
	}

	if (dp[n] >= 0)
	{
		return dp[n];
	}

	int a = 0, b = 0, x = 0;

	for (i = 0; i < n; i++)
	{
		for (j = n - i - 1; j > 0; j--)
		{
			if ((n - i) % j == 0)
			{
				a++;
			}
		}

		if (a == 1)
		{
			b++;

			if (prime(i) == 0)
			{
				x++;
			}
		}

		a = 0;
	}

	if (b == x)
	{
		return dp[n] = 1;
	}

	else
	{
		return dp[n] = 0;
	}
}

int main()
{
	int n;

	cin >> n;

	if (n == 2 || n == 3)
	{
		cout << "Lose" << endl;

		return 0;
	}

	for (i = 0; i < 10000; i++)
	{
		dp[i] = -1;
	}

	if (prime(n) == 1)
	{
		cout << "Lose" << endl;
	}

	else
	{
		cout << "Win" << endl;
	}

}
0