fn get_primes(n: usize) -> Vec { let mut flgs = vec![true; n+1]; flgs[0] = false; flgs[1] = false; for i in 2..=(n as f64).sqrt().ceil() as usize { if !flgs[i] { continue; } for j in i..=n/i { flgs[i*j] = false; } } flgs } fn main() { let mut n = String::new(); std::io::stdin().read_line(&mut n).ok(); let n: usize = n.trim().parse().unwrap(); if n == 1 { println!("0"); return; } let primes = get_primes(n); let mut result = 0usize; for q in 2..=n { if !primes[q] { continue; } let r = ((2 + q) as f64).sqrt().floor() as usize; if r * r == 2 + q && primes[r] { result += 1; } } if result == 0 { println!("0"); return; } else { println!("{}", result * 2 - 1); } }