結果

問題 No.7 プライムナンバーゲーム
ユーザー h_noson
提出日時 2016-02-16 16:33:49
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 12 ms / 5,000 ms
コード長 702 bytes
コンパイル時間 592 ms
コンパイル使用メモリ 66,192 KB
実行使用メモリ 6,820 KB
最終ジャッジ日時 2024-10-01 15:40:29
合計ジャッジ時間 1,304 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 17
権限があれば一括ダウンロードができます

ソースコード

diff #

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

bool isprime(int x) {
    if (x < 2)
        return false;
    for (int i = 2; i <= sqrt(x); i++) {
        if (x % i == 0)
            return false;
    }
    return true;
}

int main() {
    int n;
    vector<int> loselist{2,3};
    cin >> n;
    for (int i = 4; i <= n; i++) {
        bool win = false;
        for (int x : loselist) {
            if (isprime(i - x)) {
                win = true;
                break;
            }
        }
        if (!win)
            loselist.push_back(i);
    }
    if (loselist.back() == n)
        cout << "Lose" << endl;
    else
        cout << "Win" << endl;
    return 0;
}
0