結果

問題 No.1791 Repeat Multiplication
ユーザー koba-e964koba-e964
提出日時 2021-12-21 01:11:46
言語 Rust
(1.72.1)
結果
AC  
実行時間 128 ms / 3,000 ms
コード長 1,539 bytes
コンパイル時間 2,238 ms
コンパイル使用メモリ 150,672 KB
実行使用メモリ 26,156 KB
最終ジャッジ日時 2023-10-13 19:44:39
合計ジャッジ時間 5,914 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,352 KB
testcase_01 AC 1 ms
4,348 KB
testcase_02 AC 1 ms
4,348 KB
testcase_03 AC 1 ms
4,348 KB
testcase_04 AC 1 ms
4,348 KB
testcase_05 AC 1 ms
4,348 KB
testcase_06 AC 1 ms
4,352 KB
testcase_07 AC 1 ms
4,348 KB
testcase_08 AC 22 ms
4,352 KB
testcase_09 AC 21 ms
4,352 KB
testcase_10 AC 19 ms
4,348 KB
testcase_11 AC 18 ms
4,348 KB
testcase_12 AC 11 ms
4,352 KB
testcase_13 AC 115 ms
24,264 KB
testcase_14 AC 125 ms
24,772 KB
testcase_15 AC 85 ms
18,904 KB
testcase_16 AC 85 ms
18,436 KB
testcase_17 AC 127 ms
25,624 KB
testcase_18 AC 97 ms
21,004 KB
testcase_19 AC 113 ms
24,020 KB
testcase_20 AC 87 ms
19,500 KB
testcase_21 AC 111 ms
23,784 KB
testcase_22 AC 127 ms
25,544 KB
testcase_23 AC 90 ms
19,964 KB
testcase_24 AC 122 ms
24,484 KB
testcase_25 AC 110 ms
23,004 KB
testcase_26 AC 119 ms
25,084 KB
testcase_27 AC 96 ms
20,928 KB
testcase_28 AC 128 ms
26,068 KB
testcase_29 AC 125 ms
26,020 KB
testcase_30 AC 122 ms
26,024 KB
testcase_31 AC 1 ms
4,348 KB
testcase_32 AC 124 ms
26,156 KB
testcase_33 AC 128 ms
26,076 KB
testcase_34 AC 128 ms
26,076 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

use std::io::{Write, BufWriter};
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes.by_ref().map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr,) => {};
    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };
    ($next:expr, $t:ty) => ($next().parse::<$t>().expect("Parse error"));
}

fn main() {
    let out = std::io::stdout();
    let mut out = BufWriter::new(out.lock());
    macro_rules! puts {($($format:tt)*) => (let _ = write!(out,$($format)*););}
    input! {
        n: usize, q: usize,
        x: [usize; q],
    }
    let mut dp = vec![0i64; n + 1];
    dp[1] = 1;
    for i in 1..n + 1 {
        for j in 2..n / i + 1 {
            dp[i * j] += dp[i];
        }
    }
    let mut acc = vec![0; n + 1];
    for i in 1..n + 1 {
        acc[i] = acc[i - 1] + dp[i];
    }
    for x in x {
        puts!("{}\n", dp[x] * acc[n / x]);
    }
}
0