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