結果

問題 No.915 Plus Or Multiple Operation
ユーザー fukafukatanifukafukatani
提出日時 2019-10-25 22:37:07
言語 Rust
(1.72.1)
結果
WA  
実行時間 -
コード長 1,403 bytes
コンパイル時間 1,472 ms
コンパイル使用メモリ 146,312 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-07 00:27:05
合計ジャッジ時間 2,323 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 WA -
testcase_10 AC 1 ms
4,376 KB
testcase_11 WA -
testcase_12 WA -
権限があれば一括ダウンロードができます
コンパイルメッセージ
warning: unused variable: `i`
  --> Main.rs:20:9
   |
20 |     for i in 0..q {
   |         ^ help: if this is intentional, prefix it with an underscore: `_i`
   |
   = note: `#[warn(unused_variables)]` on by default

warning: 1 warning emitted

ソースコード

diff #

#![allow(unused_imports)]
#![allow(non_snake_case)]
use std::cmp::*;
use std::collections::*;
use std::io::Write;

#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), std::io::stderr());
            writeln!(err, "{} = {:?}", e, $e).unwrap()
        })*
    };
}

fn main() {
    let q = read::<usize>();
    for i in 0..q {
        let v = read_vec::<i64>();
        let (a, b, c) = (v[0], v[1], v[2]);
        if c == 1 {
            println!("{}", a * b);
            continue;
        }
        let mut ans = 0;
        let mut cur_multiplied = 1;
        let mut loop_cnt = 0;
        while cur_multiplied * c < a {
            cur_multiplied *= c;
            loop_cnt += 1;
        }
        ans += loop_cnt;
        let mut a = a;
        while a != 0 {
            a -= a / cur_multiplied * cur_multiplied;
            ans += 1;
            while cur_multiplied > a {
                cur_multiplied /= c;
            }
        }
        println!("{}", ans * b);
    }
}

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}
0