結果

問題 No.7 プライムナンバーゲーム
ユーザー gon_027gon_027
提出日時 2019-09-10 17:45:49
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,017 bytes
コンパイル時間 519 ms
コンパイル使用メモリ 67,628 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-15 13:06:27
合計ジャッジ時間 1,374 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <cmath>
using namespace std;

static const int N = 10000;
bool flag = true;

int prime[N + 1] = {0};

bool isPrime(int n){
    if(n <= 1) return false;
    else if(n == 2) return true;
    else if(n % 2 == 0) return false;

    int num = sqrt(n);
    for(int i = 3; i <= num; i += 2){
        if(n % i == 0) return false;
    }

    return true;
}

int n; 

int a = 0;

void calc(int num){
    
}

int main(){
    cin >> n;

    for(int i = 0; i <= n; i++){
        prime[i] = isPrime(i);
    }

    int a = 0;

    while(1){
        if(flag){
            if(isPrime(a)){
                n = n - a;
            }
            if(n <= 1){
                cout << "Lose" << endl;
                return 0;
            }
            flag = !flag;
        }else{
            if (isPrime(a)){
                n = n - a;
            }
            if (n <= 1){
                cout << "Win" << endl;
                return 0;
            }
            flag = !flag;
        }
        a++;
    }
}
0