結果

問題 No.2939 Sigma Popcount Problem
ユーザー naut3
提出日時 2024-10-20 22:18:38
言語 Rust
(1.83.0 + proconio)
結果
AC  
実行時間 25 ms / 2,000 ms
コード長 1,002 bytes
コンパイル時間 12,686 ms
コンパイル使用メモリ 401,264 KB
実行使用メモリ 6,820 KB
最終ジャッジ日時 2024-10-20 22:18:54
合計ジャッジ時間 14,857 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 18
権限があれば一括ダウンロードができます

ソースコード

diff #

#![allow(non_snake_case, unused_must_use, unused_imports)]
use std::io::{self, prelude::*};

fn main() {
    let (stdin, stdout) = (io::read_to_string(io::stdin()).unwrap(), io::stdout());
    let (mut stdin, mut buffer) = (stdin.split_whitespace(), io::BufWriter::new(stdout.lock()));
    for _ in 0..stdin.next().unwrap().parse::<usize>().unwrap() {
        solve(&mut stdin, &mut buffer);
    }
}

fn solve(stdin: &mut std::str::SplitWhitespace, buffer: &mut io::BufWriter<io::StdoutLock>) {
    macro_rules! input {
        ($t: ty) => {
            stdin.next().unwrap().parse::<$t>().unwrap()
        };
        ($t: ty, $n: expr) => {
            (0..$n).map(|_| input!($t)).collect::<Vec<_>>()
        };
    }

    let mut N = input!(u64);
    N += 1;

    let mut ans = 0;

    for i in 0..50 {
        ans += (N / (1 << (i + 1))) * (1 << i);

        if (N % (1 << (i + 1))) >= 1 << i {
            ans += (N % (1 << (i + 1))) - (1 << i);
        }
    }

    writeln!(buffer, "{}", ans);
}
0