結果

問題 No.251 大きな桁の復習問題(1)
ユーザー kroton
提出日時 2015-07-30 15:43:26
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 7 ms / 5,000 ms
コード長 710 bytes
コンパイル時間 574 ms
コンパイル使用メモリ 58,328 KB
実行使用メモリ 6,820 KB
最終ジャッジ日時 2024-12-17 17:23:48
合計ジャッジ時間 1,490 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 21
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
using namespace std;
typedef long long ll;
const int MOD = 129402307;

int mod(const string& S, int m){
    int res = 0;
    for(char x : S){
        res *= 10;
        res += x - '0';
        res %= m;
    }
    return res;
}

ll mod_pow(ll x, ll e, ll m){
    ll v = 1;
    for(;e;e>>=1){
        if(e & 1){
            v = (v * x) % m;
        }
        x = (x * x) % m;
    }
    return v;
}

int main(){
    string N, M;
    cin >> N >> M;
    if(M == "0"){
        cout << 1 << endl;
        return 0;
    }
    int n = mod(N, MOD);
    if(n == 0){
        cout << 0 << endl;
        return 0;
    }
    int m = mod(M, MOD - 1);
    cout << mod_pow(n, m, MOD) << endl;
    return 0;
}
0