結果

問題 No.7 プライムナンバーゲーム
ユーザー diginatudiginatu
提出日時 2014-11-24 01:50:35
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 39 ms / 5,000 ms
コード長 772 bytes
コンパイル時間 430 ms
コンパイル使用メモリ 59,080 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-04-09 03:40:43
合計ジャッジ時間 1,431 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 AC 2 ms
6,944 KB
testcase_02 AC 39 ms
6,944 KB
testcase_03 AC 3 ms
6,944 KB
testcase_04 AC 2 ms
6,944 KB
testcase_05 AC 2 ms
6,944 KB
testcase_06 AC 11 ms
6,948 KB
testcase_07 AC 7 ms
6,948 KB
testcase_08 AC 4 ms
6,944 KB
testcase_09 AC 17 ms
6,944 KB
testcase_10 AC 2 ms
6,944 KB
testcase_11 AC 7 ms
6,944 KB
testcase_12 AC 28 ms
6,944 KB
testcase_13 AC 30 ms
6,944 KB
testcase_14 AC 39 ms
6,944 KB
testcase_15 AC 38 ms
6,944 KB
testcase_16 AC 34 ms
6,948 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <cstring>
#include <vector>

using namespace std;

#include <typeinfo>

bool is_prime[10001];

void Eratosthenes(long long lim){
	memset(is_prime, 1, sizeof(is_prime));
	is_prime[0] = false;
	is_prime[1] = false;
	for(long long p=2; p*p<=lim; p++) {
		if(is_prime[p]){
			for(long long k=p*p; k<=lim; k+=p) is_prime[k] = false;
		}
	}
}

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

	Eratosthenes(N);
	bool win[10001];
	win[0] = true;
	win[1] = true;
	win[2] = false;

	for (int i = 3; i <= N; ++i) {
		win[i] = false;
		for (int j = 2; j < i; ++j) {
			if (is_prime[j]) {
				if (win[i-j] == false) {
					win[i] = true;
					break;
				}
			}
		}
	}


	cout << (win[N]?"Win":"Lose") << endl;

	return 0;
}
0