結果

問題 No.7 プライムナンバーゲーム
ユーザー t-0gat-0ga
提出日時 2019-07-11 13:28:39
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 929 bytes
コンパイル時間 441 ms
コンパイル使用メモリ 68,588 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-07 12:07:40
合計ジャッジ時間 3,718 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <cstring>
#include <math.h> 
using namespace std;
#define MAX 10001

bool dp[MAX];
bool IsPrime(int num)
{
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false; // 偶数はあらかじめ除く

    double sqrtNum = sqrt((double)num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            // 素数ではない
            return false;
        }
    }

    // 素数である
    return true;
}
int main()
{
	int N;
	cin >> N;
	
	if(N < 2)
	{
		cout << "Lose" << endl;
		return 0;
	}
	dp[0] = false;
	dp[1] = false;
	for(int i = 2 ; i <= N ; ++i)
	{
		for(int k = 2 ; k <= i ; ++k)
		{
			if(IsPrime(k) && !dp[i-k])
			{
				dp[i] = true;
				break;
			}
		}
	}
	if(dp[N]) cout << "Win" << endl;
	else      cout << "Lose" << endl;
    return 0;
}
0