結果

問題 No.16 累乗の加算
ユーザー cra77756176
提出日時 2022-12-05 22:49:24
言語 Rust
(1.83.0 + proconio)
結果
AC  
実行時間 1 ms / 5,000 ms
コード長 734 bytes
コンパイル時間 13,662 ms
コンパイル使用メモリ 380,996 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-10-12 19:10:24
合計ジャッジ時間 14,257 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 14
権限があれば一括ダウンロードができます

ソースコード

diff #

const DIVISOR: u64 = 1_000_003;

fn main() {
    let mut input = String::new();
    std::io::Read::read_to_string(&mut std::io::stdin(), &mut input).ok();
    let input: Vec<u64> = input
        .split_whitespace()
        .map(|n| n.parse().unwrap())
        .collect();

    let x = input[0];
    let mut answer = 0;

    for &a in &input[2..] {
        let mut a = a;
        let mut pow = x;
        let mut product = 1;

        while a > 0 {
            if a & 1 == 1 {
                product *= pow;
                product %= DIVISOR;
            }
            pow *= pow;
            pow %= DIVISOR;

            a >>= 1;
        }

        answer += product;
        answer %= DIVISOR;
    }

    println!("{}", answer);
}
0