結果

問題 No.7 プライムナンバーゲーム
ユーザー nenuonnenuon
提出日時 2017-03-01 16:40:13
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,138 bytes
コンパイル時間 564 ms
コンパイル使用メモリ 76,956 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-03 15:08:19
合計ジャッジ時間 1,378 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
using namespace std;

#define ll         long long
#define PI         acos(-1.0)
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)

//方針


vector<int> vp;

//素数作成
void MakePrimeNumber(int n){
    vp.clear();
    int tmp[n+1];
    FOR(i, 0, n+1) tmp[i] = 0;
    FOR(i, 0, n+1) tmp[i] = 1;
    FOR(i, 2, n+1){
        if(tmp[i]==0) continue;
        vp.push_back(i);
        int j = i;
        while(j <= n){
            tmp[j] = 0;
            j += i;
        }
    }
}

void dfs(int n, int me){
    if(n==2 || n==3){
        if(me==1) cout << "Lose" << endl;
        else cout << "Win" << endl;
        return;
    }
    int j = 0;
    int prime = 0;
    while(1){
        if(n-vp[j]>=2) prime = vp[j];
        else break;
        j++;
        if(j==vp.size()) break;
    }
    dfs(n-prime, (me+1)%2);
}

int main(){
  int N;
  cin >> N;
  MakePrimeNumber(N);
  dfs(N, 1);
}
0