結果

問題 No.7 プライムナンバーゲーム
ユーザー keikei
提出日時 2016-08-11 22:59:45
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 475 ms / 5,000 ms
コード長 689 bytes
コンパイル時間 570 ms
コンパイル使用メモリ 69,772 KB
実行使用メモリ 6,696 KB
最終ジャッジ日時 2024-04-09 04:02:06
合計ジャッジ時間 4,138 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,564 KB
testcase_01 AC 1 ms
6,692 KB
testcase_02 AC 475 ms
6,692 KB
testcase_03 AC 13 ms
6,692 KB
testcase_04 AC 3 ms
6,688 KB
testcase_05 AC 4 ms
6,692 KB
testcase_06 AC 96 ms
6,692 KB
testcase_07 AC 56 ms
6,692 KB
testcase_08 AC 19 ms
6,692 KB
testcase_09 AC 165 ms
6,692 KB
testcase_10 AC 2 ms
6,692 KB
testcase_11 AC 57 ms
6,692 KB
testcase_12 AC 308 ms
6,692 KB
testcase_13 AC 333 ms
6,688 KB
testcase_14 AC 470 ms
6,692 KB
testcase_15 AC 440 ms
6,696 KB
testcase_16 AC 398 ms
6,692 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <cmath>
#include <iomanip>

using namespace std;
bool dp[10001];
int calc(int num) {
	if (num - 2 >= 0) {
		if (dp[num - 2] == false) {
			return true;
		}
	}
	for (int i = 3; i <= num; i += 2) {
		int k = 0;
		for (int j = 3; j <= sqrt(i); j += 2) {
			if (i%j == 0) {
				k = 1;
				break;
			}
		}
		if (k == 0) {
			if (num - i >= 0) {
				if (dp[num - i] == false) {
					return true;
				}
			}
		}
	}
	return false;
}

int main() {
	int num;
	cin >> num;
	dp[0] = true; dp[1] = true;
	for (int i = 2; i <= num; i++) {
		dp[i] = calc(i);
	}
	if (dp[num] == true) { cout << "Win" << endl; }
	else { cout << "Lose" << endl; }
	return 0;
}
0