結果

問題 No.251 大きな桁の復習問題(1)
ユーザー tottoripaper
提出日時 2015-07-24 22:59:13
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 12 ms / 5,000 ms
コード長 643 bytes
コンパイル時間 457 ms
コンパイル使用メモリ 55,680 KB
実行使用メモリ 6,820 KB
最終ジャッジ日時 2024-12-17 17:07:51
合計ジャッジ時間 1,289 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 21
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>

typedef long long ll;

const ll MOD = 129402307ll;
std::string N, M;

ll mod(const std::string& s, ll m){
    ll res = 0ll;
    for(int i=0;i<s.size();i++){
        res = (res * 10 % m + s[i] - '0') % m;
    }
    return res;
}

ll expt(ll a, ll n, ll m){
    ll res = 1ll;
    while(n > 0){
        if(n & 1){res = res * a % m;}
        n >>= 1;
        a = a * a % m;
    }

    return res;
}

int main(){
    std::cin >> N;
    std::cin >> M;

    ll n = mod(N, MOD), m = mod(M, MOD-1);
    if(n == 0){
        std::cout << (M == "0") << std::endl;
    }else{
        std::cout << expt(n, m, MOD) << std::endl;
    }
}
0