#![allow(unused_imports)] #![allow(non_snake_case)] use std::cmp::*; use std::collections::*; use std::io::Write; #[allow(unused_macros)] macro_rules! debug { ($($e:expr),*) => { #[cfg(debug_assertions)] $({ let (e, mut err) = (stringify!($e), std::io::stderr()); writeln!(err, "{} = {:?}", e, $e).unwrap() })* }; } fn main() { let x = read::(); let mut count = vec![0; x as usize + 1]; let primes = get_primes(x + 1); for i in 1..x { let fact = factorize(i, &primes); count[i as usize] = fact.values().fold(1, |x, &s| x * (1 + s)); } let f = |n: i64| n - count[n as usize]; let min_fab = (1..x).map(|i| (f(i) - f(x - i)).abs()).min().unwrap(); for i in 1..x { if (f(i) - f(x - i)).abs() == min_fab { println!("{} {}", i, x - i); } } } fn read() -> T { let mut s = String::new(); std::io::stdin().read_line(&mut s).ok(); s.trim().parse().ok().unwrap() } fn read_vec() -> Vec { read::() .split_whitespace() .map(|e| e.parse().ok().unwrap()) .collect() } fn get_primes(n: i64) -> Vec { let mut is_prime = vec![true; n as usize + 1]; let mut primes = Vec::new(); is_prime[0] = false; is_prime[1] = false; for i in 2..n + 1 { if is_prime[i as usize] { primes.push(i); let mut j = 2 * i; while j < n { is_prime[j as usize] = false; j += i; } } } primes } fn factorize(mut num: i64, primes: &Vec) -> std::collections::HashMap { // max_primes >= (num)^(1/2) let mut dict = std::collections::HashMap::new(); for &p in primes.iter() { while num % p == 0 { *dict.entry(p).or_insert(0) += 1; num /= p; } if num == 1 { break; } } if num != 1 { dict.insert(num, 1); } dict }