fn get_primes(max: usize) -> Vec { let mut is_prime = vec![true; max + 1]; is_prime[0] = false; is_prime[1] = false; for n in 2..=max { if !is_prime[n] { continue; } if n * n > max { break; } for i in ((n * n)..=max).step_by(n) { is_prime[i] = false; } } (0..=max).filter(|&n| is_prime[n]).collect() } fn get_n_divisors(max: usize, primes: &[usize]) -> Vec { let mut n_divisors = vec![1; max + 1]; for n in 2..=max { let mut n_tmp = n; for &p in primes { if p * p > n_tmp { break; } if n_tmp % p == 0 { let mut n_p = 1; while n_tmp % p == 0 { n_tmp /= p; n_p += 1; } n_divisors[n] *= n_p; } } if n_tmp > 1 { n_divisors[n] *= 2; } } n_divisors } fn main() { let mut xx = String::new(); std::io::stdin().read_line(&mut xx).ok(); let xx: Vec<&str> = xx.split_whitespace().collect(); let n: usize = xx[0].parse().unwrap(); let p: f64 = xx[1].parse().unwrap(); let q = 1. - p; let primes = get_primes(n); let n_divisors = get_n_divisors(n, &primes); println!( "{}", (2..=n) .map(|i| q.powi(n_divisors[i] as i32 - 2)) .sum::() ); }