結果

問題 No.7 プライムナンバーゲーム
ユーザー nanaenanae
提出日時 2017-03-02 21:04:23
言語 D
(dmd 2.107.1)
結果
TLE  
実行時間 -
コード長 865 bytes
コンパイル時間 706 ms
コンパイル使用メモリ 106,412 KB
実行使用メモリ 7,580 KB
最終ジャッジ日時 2023-09-03 01:41:43
合計ジャッジ時間 7,190 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

import std.stdio;
import std.string, std.conv, std.array, std.algorithm;
import std.range, std.uni, std.math, std.container;
import core.bitop, std.datetime;

void main(){
    int N = readln.chomp.to!int;
    auto primes = get_primes(N);
    //primes.array.writeln;
    auto judge = game(N, primes.array);
    writeln(judge ? "Win" : "Lose");
}

bool game(int N, int[] primes){
    bool ret = false;
    if(N <= 1) return true;

    foreach(i ; primes){
        if(i > N) break;
        ret |= !game(N - i, primes);
    }

    return ret;
}

auto get_primes(int N){
    auto sieve = new bool[](N);
    sieve[] = true;
    sieve[0] = sieve[1] = false;

    foreach(p ; 2 .. N){
        if(p*p > N) break;
        if(!sieve[p]) continue;
        foreach(d ; iota(p*p, N, p)){
            sieve[d] = false;
        }
    }

    return iota(N).filter!(a => sieve[a]);
}
0