結果

問題 No.7 プライムナンバーゲーム
ユーザー h_nosonh_noson
提出日時 2016-02-16 16:33:49
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 13 ms / 5,000 ms
コード長 702 bytes
コンパイル時間 647 ms
コンパイル使用メモリ 66,764 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-04-09 03:55:01
合計ジャッジ時間 1,510 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

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