結果

問題 No.7 プライムナンバーゲーム
ユーザー GOTKAKO
提出日時 2024-05-06 23:59:49
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 5 ms / 5,000 ms
コード長 724 bytes
コンパイル時間 1,801 ms
コンパイル使用メモリ 199,068 KB
最終ジャッジ日時 2025-02-21 11:30:45
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 17
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    int N; cin >> N;
    int Need = N;
    vector<int> allp;
    vector<bool> prime(Need+1,true);
    prime.at(0) = false; prime.at(1) = false;
    for(int i=2; i<=Need; i++){
        if(!prime.at(i)) continue;
        allp.push_back(i);
        for(long long k=((long long)i)*i; k<=Need; k+=i) prime.at(k) = false;
    }

    vector<bool> win(N+1);
    win.at(0) = true; win.at(1) = true;
    for(int i=2; i<=N; i++) for(auto p : allp){
        if(p > i) break;
        if(win.at(i-p) == false){win.at(i) = true; break;}
    }
    if(win.at(N)) cout << "Win" << endl;
    else cout << "Lose" << endl;
}
0