結果

問題 No.251 大きな桁の復習問題(1)
ユーザー tottoripapertottoripaper
提出日時 2015-07-24 22:59:13
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 7 ms / 5,000 ms
コード長 643 bytes
コンパイル時間 354 ms
コンパイル使用メモリ 53,356 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-22 16:47:59
合計ジャッジ時間 1,357 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 7 ms
4,380 KB
testcase_10 AC 7 ms
4,376 KB
testcase_11 AC 7 ms
4,376 KB
testcase_12 AC 7 ms
4,380 KB
testcase_13 AC 7 ms
4,376 KB
testcase_14 AC 7 ms
4,380 KB
testcase_15 AC 7 ms
4,384 KB
testcase_16 AC 7 ms
4,376 KB
testcase_17 AC 7 ms
4,376 KB
testcase_18 AC 7 ms
4,380 KB
testcase_19 AC 7 ms
4,376 KB
testcase_20 AC 1 ms
4,380 KB
testcase_21 AC 2 ms
4,376 KB
testcase_22 AC 2 ms
4,376 KB
testcase_23 AC 1 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

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