アルゴリズムと数学 012

https://atcoder.jp/contests/math-and-algorithm/tasks/math_and_algorithm_l

ミラー・ラビンを実装する余裕がないので、2から割っておきます。

// Primality Test
#![allow(non_snake_case)]


//////////////////// library ////////////////////

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

fn YesNo(b: bool) -> String {
    return if b { "Yes".to_string() } else { "No".to_string() }
}


//////////////////// process ////////////////////

fn f(N: i64) -> bool {
    (2..).take_while(|p| p * p <= N).all(|p| N % p != 0)
}

fn main() {
    let N: i64 = read();
    println!("{}", YesNo(f(N)))
}