結果
| 問題 |
No.642 Two Operations No.1
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2018-10-08 13:10:29 |
| 言語 | Rust (1.83.0 + proconio) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,040 bytes |
| コンパイル時間 | 10,977 ms |
| コンパイル使用メモリ | 403,332 KB |
| 実行使用メモリ | 6,820 KB |
| 最終ジャッジ日時 | 2024-10-12 14:35:39 |
| 合計ジャッジ時間 | 11,988 ms |
|
ジャッジサーバーID (参考情報) |
judge / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 6 WA * 9 |
ソースコード
use std::io::{ self, prelude::* };
fn clp2(mut x: u64) -> u64 {
assert!(x > 0);
x -= 1;
x |= x >> 1;
x |= x >> 2;
x |= x >> 4;
x |= x >> 8;
x |= x >> 16;
x |= x >> 32;
x + 1
}
fn ntz(mut x: u64) -> u64 {
if x == 0 { return 64; }
let mut n = 1;
if (x & 0x00000000FFFFFFFF) == 0 { n += 32; x >>= 32; }
if (x & 0x000000000000FFFF) == 0 { n += 16; x >>= 16; }
if (x & 0x00000000000000FF) == 0 { n += 8; x >>= 8; }
if (x & 0x000000000000000F) == 0 { n += 4; x >>= 4; }
if (x & 0x0000000000000003) == 0 { n += 2; x >>= 2; }
n - (x & 1)
}
fn f(mut n: u64) -> (u64, u64) {
let mut a = 0;
while n % 2 == 0 {
n /= 2;
a += 1;
}
(a, n)
}
fn main() {
let mut s = String::new();
io::stdin().read_to_string(&mut s).unwrap();
let mut tokens = s.split_whitespace();
let n: u64 = tokens.next().unwrap().parse().unwrap();
let (a, b) = f(n);
let c = clp2(b);
let ans = ntz(c) + c-b + a;
println!("{}", ans);
}