結果

問題 No.7 プライムナンバーゲーム
ユーザー iwotiwot
提出日時 2019-08-15 20:17:55
言語 Rust
(1.77.0)
結果
WA  
実行時間 -
コード長 1,131 bytes
コンパイル時間 4,959 ms
コンパイル使用メモリ 166,020 KB
実行使用メモリ 4,372 KB
最終ジャッジ日時 2023-10-19 19:20:00
合計ジャッジ時間 5,846 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,348 KB
testcase_01 AC 1 ms
4,372 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 AC 1 ms
4,372 KB
testcase_06 WA -
testcase_07 WA -
testcase_08 AC 3 ms
4,372 KB
testcase_09 AC 10 ms
4,372 KB
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 AC 16 ms
4,372 KB
testcase_14 AC 20 ms
4,372 KB
testcase_15 AC 20 ms
4,372 KB
testcase_16 WA -
権限があれば一括ダウンロードができます
コンパイルメッセージ
warning: unused variable: `msg`
  --> Main.rs:36:13
   |
36 |     let mut msg = "";
   |             ^^^ help: if this is intentional, prefix it with an underscore: `_msg`
   |
   = note: `#[warn(unused_variables)]` on by default

warning: variable does not need to be mutable
  --> Main.rs:36:9
   |
36 |     let mut msg = "";
   |         ----^^^
   |         |
   |         help: remove this `mut`
   |
   = note: `#[warn(unused_mut)]` on by default

warning: 2 warnings emitted

ソースコード

diff #

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn primes(n:usize) -> Vec<usize> {
    let mut result = vec![];
    if n >= 2 {
        for i in 2..=n {
            if i == 2 {
                result.push(i);
            } else if i % 2 != 0 {
                let mut is_prime = true;
                for j in 2..i {
                    if i % j == 0 {
                        is_prime = false;
                        break;
                    }
                }
                if is_prime {
                    result.push(i);
                }
            }
        }
    }
    result
}

fn main() {
    let n:usize = read();

    let primes = primes(n);

    let start = primes.len();
    let mut msg = "";
    let mut win = false;
    for i in (0..start).rev() {
        if n - primes[i] < 5 && n - primes[i] > 1 {
            win = true;
            break;
        } else if n - primes[i] >= 5 {
            break;
        }
    }
    if win {
        println!("Win");
    } else {
        println!("Lose");
    }
}

0