結果

問題 No.7 プライムナンバーゲーム
ユーザー noriocnorioc
提出日時 2019-05-05 08:30:27
言語 D
(dmd 2.107.1)
結果
AC  
実行時間 3 ms / 5,000 ms
コード長 1,062 bytes
コンパイル時間 625 ms
コンパイル使用メモリ 92,068 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-04 01:05:51
合計ジャッジ時間 1,676 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

import std.algorithm;
import std.array;
import std.conv;
import std.math;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

T read(T)() { return readln.chomp.to!T; }
T[] reads(T)() { return readln.split.to!(T[]); }
alias readint = read!int;
alias readints = reads!int;

int[] sieve(int n) {
    assert(n > 1);
    auto t = new bool[n + 1];
    int[] primes = [2];
    for (int i = 3; i < t.length; i += 2) {
        if (!t[i]) {
            primes ~= i;
            for (int j = i + i; j < t.length; j += i)
                t[j] = true;
        }
    }
    return primes;
}

void main() {
    int n = readint;

    bool[] table = new bool[n + 1];
    table[0] = table[1] = false; // 負け
    auto primes = sieve(n);
    for (int i = 2; i <= n; i++) {
        if (!table[i]) { // 負け
            foreach (p; primes) {
                if (i + p > n) break;

                // 負け遷移にもっていけるなら勝ち
                table[i + p] = true;
            }
        }
    }
    writeln(table[n] ? "Win" : "Lose");
}
0