結果

問題 No.7 プライムナンバーゲーム
ユーザー mottodoramottodora
提出日時 2016-10-30 09:47:25
言語 Rust
(1.77.0)
結果
WA  
実行時間 -
コード長 996 bytes
コンパイル時間 703 ms
コンパイル使用メモリ 146,596 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-16 11:14:31
合計ジャッジ時間 1,730 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

fn getline() -> String{
    let mut ret = String::new();
    std::io::stdin().read_line(&mut ret).ok();
    return ret;
}

fn eratosthenes(n: i32) -> Vec<i32> {
    let mut v: Vec<i32> = (2..n+1).collect();
    let mut i:i32 = 0;
    while i < v.len() as i32 {
        let a = v[i as usize];
        v.retain(|&x| x< a+1 || x % a !=0);
        i+=1;
    }
    v
}

fn max_prime(n: i32, primes: &Vec<i32>) -> i32 {
    let mut i: i32 = 0;
    let l = primes.len() as i32;
    if n >= primes[(l-1) as usize] {
        primes[(l-1) as usize]
    }
    else {
        while primes[(i+1) as usize] <= n {
            i += 1;
        }
        primes[i as usize]
    }
}

fn main() {
    let n: i32 = getline().trim().parse().unwrap();
    let primes = eratosthenes(n);
    let mut dp = [false; 10001];

    for i in 4..(n+1) {
        dp[i as usize] = !dp[(i-max_prime(i-2, &primes)) as usize];
    }

    if dp[n as usize] {
        println!("Win");
    }
    else {
        println!("Lose");
    }
}
0