AtCoder Beginner Contest 389 D

https://atcoder.jp/contests/abc389/tasks/abc389_d

x=0.5, 1.5, ...のときの円周のy座標を調べるとよいです。

// Squares in Circle
#![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()
}


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

fn F(R: i64) -> i64 {
    let mut counter: i64 = 0;
    for i in 0..R {
        let x: f64 = (i as f64) + 0.5;
        let y = ((R*R) as f64 - x*x).sqrt();
        let n = (y + 0.5).floor() as i64;
        if i == 0 {
            counter += n * 2 - 1
        }
        else {
            counter += n * 4 - 2
        }
    }
    counter
}

fn main() {
    let R: i64 = read();
    println!("{}", F(R))
}