結果

問題 No.7 プライムナンバーゲーム
ユーザー rodearodea
提出日時 2017-12-08 21:23:11
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 806 bytes
コンパイル時間 748 ms
コンパイル使用メモリ 68,352 KB
実行使用メモリ 8,704 KB
最終ジャッジ日時 2024-05-07 05:42:13
合計ジャッジ時間 14,259 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 TLE -
testcase_04 AC 626 ms
5,376 KB
testcase_05 AC 599 ms
5,376 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)
			{
				break;
			}
		}

		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