fn calc(start: usize, times: usize) -> usize { let mut val = start; let mut ret = 0usize; for _ in 0..times { ret += val; val /= 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 i in 1..=61 { let mut lower = 1usize; let mut upper = d; while upper > lower { let middle = (upper + lower) / 2; let val = calc(middle, i); if val >= d { upper = middle; } else { lower = middle + 1; } } if calc(upper, i) == d { result = result.min(upper); } } println!("{}", result); }