結果

問題 No.1140 EXPotentiaLLL!
ユーザー pmpm
提出日時 2020-07-31 22:55:13
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,327 bytes
コンパイル時間 2,889 ms
コンパイル使用メモリ 172,040 KB
実行使用メモリ 12,176 KB
最終ジャッジ日時 2023-09-21 01:41:07
合計ジャッジ時間 8,997 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 TLE -
testcase_01 -- -
testcase_02 -- -
testcase_03 -- -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>; 
using pll = pair<long long, long long>;
constexpr char ln =  '\n';
constexpr long long MOD = 1000000007LL;
constexpr long long INF = 1001001001LL;
constexpr long long LINF = 1001001001001001001;
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define rept(i, j, n) for(int i=(j); i<(n); i++)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

bool is_prime(long long N) {
    if (N == 1) return false;
    for (long long i = 2; i * i <= N; ++i) {
        if (N % i == 0) return false;
    }
    return true;
}

ll rui(ll a,ll b, ll mod){
     ll ans=1;
     while(b>0){
        if(b&1) ans=ans*a%mod;
        a=a*a%mod;
        b/=2;
    }
     return ans;
}

int main(){
    int T; cin >> T;
    rep(test, T){
        ll A, P; cin >> A >> P;
        if(is_prime(P)){
            ll res = 1;
            for(int i=P; i>0; i--){
                ll tmp = rui(A, i, P);
                res = (res * tmp) % P;
            }
            cout << res << ln;
            
        }else{
            cout << -1 << ln;
        }

    }
}
    
 
0