結果

問題 No.251 大きな桁の復習問題(1)
コンテスト
ユーザー あるふぁ
提出日時 2026-09-28 20:34:49
言語 Rust
(1.97.1 + proconio + num + itertools + ACL)
コンパイル:
/usr/bin/rustc_custom
実行:
./target/release/main
結果
AC  
実行時間 2 ms / 5,000 ms
+ 171µs
コード長 774 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 529 ms
コンパイル使用メモリ 189,300 KB
実行使用メモリ 9,920 KB
最終ジャッジ日時 2026-09-28 20:34:54
合計ジャッジ時間 2,433 ms
ジャッジサーバーID
(参考情報)
judge1_0 / judge3_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 21
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

use proconio::input;

const MOD: i64 = 129402307;

fn modpow(mut a: i64, mut e: i64, m: i64) -> i64{
    let mut r: i64 = 1;
    while e > 0{
        if e&1 == 1{
            r = r*a%m;
        }
        a = a*a%m;
        e >>= 1;
    }
    r
}

fn main(){
    input!{
        n: String,
        m: String,
    }

    if m == String::from("0"){
        println!("{}", 1);
        return;
    }

    let mut a: i64 = 0;
    for c in n.chars(){
        a *= 10;
        a += c.to_digit(10).unwrap() as i64;
        a %= MOD;
    }

    if a == 0{
        println!("{}", 0);
        return;
    }

    let mut e: i64 = 0;
    for c in m.chars(){
        e *= 10;
        e += c.to_digit(10).unwrap() as i64;
        e %= MOD-1;
    }

    println!("{}", modpow(a, e, MOD));
}
0