結果

問題 No.7 プライムナンバーゲーム
ユーザー taotao54321taotao54321
提出日時 2018-10-14 22:11:44
言語 Rust
(1.77.0)
結果
AC  
実行時間 45 ms / 5,000 ms
コード長 1,041 bytes
コンパイル時間 639 ms
コンパイル使用メモリ 163,868 KB
実行使用メモリ 6,696 KB
最終ジャッジ日時 2024-04-09 04:31:53
合計ジャッジ時間 1,692 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#![allow(non_snake_case)]

use std::io::{ self, prelude::* };

macro_rules! pick {
    ($tokens:expr) => {
        $tokens.next().unwrap().parse().expect("parse error")
    }
}

fn eratos(N: usize) -> Vec<bool> {
    let mut prime = vec![true; N+1];
    prime[0] = false;
    prime[1] = false;

    for i in 2..=N {
        if !prime[i] { continue; }

        for j in (2*i..).step_by(i) {
            if j > N { break; }
            prime[j] = false;
        }
    }

    prime
}

fn main() {
    let mut s = String::new();
    io::stdin().read_to_string(&mut s).expect("i/o error");
    let mut tokens = s.split_whitespace();

    let N: usize = pick!(tokens);

    let prime = eratos(N);

    let mut win = vec![false; N+1];
    win[0] = true;
    win[1] = true;
    for i in 2..=N {
        for j in 2..i {
            if !prime[j] { continue; }
            if !win[i-j] {
                win[i] = true;
                break;
            }
        }
    }

    let ans = win[N];

    println!("{}", if ans { "Win" } else { "Lose" });
}
0