use std::io::{stdout, BufReader, BufWriter, Read, Write}; #[allow(unused_macros)] macro_rules! input { (source = $s:expr, $($r:tt)*) => { let mut iter = $s.split_whitespace(); let mut next = || { iter.next().unwrap() }; input_inner!{next, $($r)*} }; ($($r:tt)*) => { let stdin = std::io::stdin(); let mut bytes = Read::bytes(BufReader::new(stdin.lock())); let mut next = move || -> String{ bytes .by_ref() .map(|r|r.unwrap() as char) .skip_while(|c|c.is_whitespace()) .take_while(|c|!c.is_whitespace()) .collect() }; input_inner!{next, $($r)*} }; } #[allow(unused_macros)] macro_rules! input_inner { ($next:expr) => {}; ($next:expr, ) => {}; ($next:expr, $var:ident : $t:tt $($r:tt)*) => { let $var = read_value!($next, $t); input_inner!{$next $($r)*} }; ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => { let mut $var = read_value!($next, $t); input_inner!{$next $($r)*} }; } #[allow(unused_macros)] macro_rules! read_value { ($next:expr, ( $($t:tt),* )) => { ( $(read_value!($next, $t)),* ) }; ($next:expr, [ $t:tt ; $len:expr ]) => { (0..$len).map(|_| read_value!($next, $t)).collect::>() }; ($next:expr, chars) => { read_value!($next, String).chars().collect::>() }; ($next:expr, bytes) => { read_value!($next, String).into_bytes() }; ($next:expr, usize1) => { read_value!($next, usize) - 1 }; ($next:expr, $t:ty) => { $next().parse::<$t>().expect("Parse error") }; } fn main() { let out = stdout(); let mut writer = BufWriter::new(out.lock()); solve(&mut writer); writer.flush().unwrap(); } fn solve(mut writer: W) { #[allow(unused_macros)] macro_rules! print { ($fmt:expr) => { write!(writer, $fmt).unwrap() }; ($fmt:expr, $($arg:tt)*) => { write!(writer, $fmt, $($arg)*).unwrap() }; } #[allow(unused_macros)] macro_rules! println { ($fmt:expr) => { writeln!(writer, $fmt).unwrap() }; ($fmt:expr, $($arg:tt)*) => { writeln!(writer, $fmt, $($arg)*).unwrap() }; } // Main Code input! { d: usize } let mut vec = Vec::new(); for num in 1..=64 { let mut l = d / 2; let mut r = d + 1; while r - l > 1 { let mid = (l + r) / 2; if dist(mid, num) <= d { l = mid; } else { r = mid; } } if dist(l, num) == d { vec.push(l); } } println!("{}", vec.iter().min().unwrap()); } fn dist(x: usize, num: usize) -> usize { let mut sum = 0; let mut y = x; for _ in 0..num { sum += y; y /= 2; } sum }