結果

問題 No.16 累乗の加算
ユーザー tabataba
提出日時 2024-08-02 11:04:12
言語 Rust
(1.77.0)
結果
AC  
実行時間 1 ms / 5,000 ms
コード長 520 bytes
コンパイル時間 11,847 ms
コンパイル使用メモリ 401,880 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-08-02 11:04:28
合計ジャッジ時間 13,300 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,812 KB
testcase_01 AC 1 ms
6,812 KB
testcase_02 AC 1 ms
6,944 KB
testcase_03 AC 1 ms
6,944 KB
testcase_04 AC 1 ms
6,940 KB
testcase_05 AC 1 ms
6,944 KB
testcase_06 AC 1 ms
6,940 KB
testcase_07 AC 1 ms
6,944 KB
testcase_08 AC 1 ms
6,940 KB
testcase_09 AC 1 ms
6,940 KB
testcase_10 AC 1 ms
6,940 KB
testcase_11 AC 1 ms
6,944 KB
testcase_12 AC 1 ms
6,940 KB
testcase_13 AC 1 ms
6,944 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

const MOD: u64 = 1000003;
fn main() {
    proconio::input! {
        x: u64,
        n: u64,
        a: [u64; n],
    }
    let ans = a.iter().map(|a| pow_mod(x, *a, MOD)).fold(0, |acc, x| {
        eprintln!("{x}");
        (acc + x) % MOD
    });
    println!("{ans}");
}

fn pow_mod(a: u64, b: u64, c: u64) -> u64 {
    let mut a = a;
    let mut b = b;
    let mut res = 1;
    while b > 0 {
        if b % 2 == 1 {
            res = (res * a) % c;
        }
        a = (a * a) % c;
        b /= 2;
    }
    res
}
0