fn dist(first: usize, times: usize) -> usize { let mut ret = first; let mut base = first/2; for _ in 0..times { ret += base; base /= 2; } ret } fn main() { let mut d = String::new(); std::io::stdin().read_line(&mut d).ok(); let d: usize = d.trim().parse().unwrap(); let mut result = d; for times in 1..32 { let mut lower = 1usize; let mut upper = d; while upper > lower { let middle = (upper + lower) / 2; if dist(middle, times) < d { lower = middle+1; } else { upper = middle; } } if dist(upper, times) == d { result = result.min(upper); } } println!("{}", result); }