fn main() { let stdin = std::io::stdin(); let mut rd = ProconReader::new(stdin.lock()); let d: i64 = rd.get(); for y in ((d / 2 - 100000)..=(d / 2 + 100000)).filter(|&y| 1 <= y && y <= d) { if (0..60) .scan((0, y), |(s, x), _| { *s += *x; *x /= 2; Some((*s, *x)) }) .any(|(s, _)| s == d) { println!("{}", y); return; } } unreachable!(); } pub struct ProconReader { reader: R, } impl ProconReader { pub fn new(reader: R) -> Self { Self { reader } } pub fn get(&mut self) -> T { use std::io::Read; let buf = self .reader .by_ref() .bytes() .map(|b| b.unwrap()) .skip_while(|&byte| byte == b' ' || byte == b'\n' || byte == b'\r') .take_while(|&byte| byte != b' ' && byte != b'\n' && byte != b'\r') .collect::>(); std::str::from_utf8(&buf) .unwrap() .parse() .ok() .expect("Parse Error.") } }