結果

問題 No.378 名声値を稼ごう
ユーザー AyachiGinAyachiGin
提出日時 2016-06-20 19:40:54
言語 Rust
(1.77.0)
結果
AC  
実行時間 1 ms / 2,000 ms
コード長 488 bytes
コンパイル時間 379 ms
コンパイル使用メモリ 141,324 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-12 00:53:28
合計ジャッジ時間 961 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

use std::io;

fn main() {
    let mut input = String::new();
    io::stdin().read_line(&mut input)
        .expect("Read error");
    let n: u64 = input.trim().parse().unwrap();
    println!("{}", solve(n));
}

fn solve(n: u64) -> u64 {
    let mut acc: u64 = 0;
    let mut n2 = n;

    loop {
        if n2 == 0 { break; }

        acc += n2;
        n2 /= 2;
    }
    2*n - acc
}

#[test]
fn it_works() {
    assert_eq!(2, solve(12));
    assert_eq!(31, solve(123456789123456789));
}
0