use std::io::*; use std::str::FromStr; fn main() { exec(read()); } fn exec(i: i64) { println!( "{}", match i { 1 => 0, _ => count_tap(i), } ); } fn count_tap(i: i64) -> i64 { if i % 2 == 0 { return calculate_count_tap(i); } else { calculate_count_tap(i - 1) + 1 } } fn calculate_count_tap(i: i64) -> i64 { let i_bin = format!("{:b}", i); let count_pow = binary_string_len(&i_bin) - 1; let a = pow_two(count_pow, 1); if i - a == 0 { return count_pow; } else { count_pow + 1 } } fn binary_string_len(s: &String) -> i64 { s.len() as i64 } fn pow_two(i: i64, mut acc: i64) -> i64 { if i == 0 { return acc; } else { acc = acc * 2; pow_two(i - 1, acc) } } fn read() -> T { let stdin = stdin(); let stdin = stdin.lock(); let token: String = stdin .bytes() .map(|c| c.expect("failed to read char") as char) .skip_while(|c| c.is_whitespace()) .take_while(|c| !c.is_whitespace()) .collect(); token.parse().ok().expect("failed to parse token") }