結果

問題 No.7 プライムナンバーゲーム
ユーザー t-0gat-0ga
提出日時 2019-07-11 13:37:02
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 928 bytes
コンパイル時間 487 ms
コンパイル使用メモリ 67,536 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-25 06:09:16
合計ジャッジ時間 7,876 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

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