結果

問題 No.251 大きな桁の復習問題(1)
ユーザー codershifthcodershifth
提出日時 2016-05-03 14:22:07
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 4 ms / 5,000 ms
コード長 1,609 bytes
コンパイル時間 1,700 ms
コンパイル使用メモリ 145,996 KB
実行使用メモリ 4,388 KB
最終ジャッジ日時 2023-08-22 17:10:05
合計ジャッジ時間 2,871 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>

typedef long long ll;
typedef unsigned long long ull;

#define FOR(i,a,b) for(int (i)=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define RANGE(vec) (vec).begin(),(vec).end()

using namespace std;

long long  mpow(long long a, long long k, long long M)
{
        long long  b = 1LL;
        while (k > 0)
        {
            if (k & 1LL)
                b = (b*a)%M;
            a = (a*a)%M;
            k >>= 1;
        }
        return b;
}


class BigDigitProblem
{
public:
    void solve(void)
    {
        string N,M;
        cin>>N>>M;

        const ll Mod = 129402307;

        // Farmat Theorem より
        // N^M = N^(M%(Mod-1)) なので
        // N,M は N%Mod, M%(Mod-1) に置き換えられる
        // 後は高速ベキ乗計算

        ll n,m;
        n = m = 0;
        for (auto c : N)
        {
            n *= 10;
            n += c-'0';
            n %= Mod;
        }
        for (auto c : M)
        {
            m *= 10;
            m += c-'0';
            m %= (Mod-1);
        }
        if ( N == "0" )
        {
            assert(M != "0");   // 制約
            cout<<0<<endl;
            return;
        }
        if ( M == "0")
        {
            cout<<1<<endl;
            return;
        }
        if ( n == 0 )
        {
            cout<<0<<endl;
            return;
        }
        // log(M)
        cout<<mpow(n,m,Mod)<<endl;

    }
};

#if 1
int main(int argc, char *argv[])
{
        ios::sync_with_stdio(false);
        auto obj = new BigDigitProblem();
        obj->solve();
        delete obj;
        return 0;
}
#endif
0