結果

問題 No.1140 EXPotentiaLLL!
ユーザー tabae326tabae326
提出日時 2020-07-31 23:10:23
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 797 bytes
コンパイル時間 1,502 ms
コンパイル使用メモリ 165,364 KB
実行使用メモリ 8,532 KB
最終ジャッジ日時 2023-09-21 02:21:05
合計ジャッジ時間 17,615 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 TLE -
testcase_01 AC 1,342 ms
8,156 KB
testcase_02 TLE -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 TLE -
testcase_08 AC 165 ms
8,208 KB
testcase_09 AC 162 ms
8,296 KB
testcase_10 WA -
testcase_11 WA -
testcase_12 AC 170 ms
8,204 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, srt, end) for (long long i = (srt); i < (long long)(end); i++)

#define NMAX 5000100
bool primes[NMAX];

ll mod_pow(ll a, ll n, ll mod){
    ll ret = 1;
    while(n > 0){
        if(n & 1) ret = (ret*(a % mod))%mod;
        a = ((a%mod)*(a%mod)) % mod;
        n = n >> 1;
    }
    return ret;
}
int main(){
    rep(i, 2, NMAX) primes[i] = true;
    rep(i, 2, NMAX) {
        for(ll j = i * 2; j <= NMAX; j += i) primes[j] = false;
    }
    ll T = 0;
    cin >> T;
    rep(test, 0, T){
        ll a, p;
        cin >> a >> p;
        if(!primes[p]) {
            cout << -1 << endl;
            continue;
        }
        ll ans = mod_pow(a, p * (p+1) / 2, p);
        cout << ans << endl;
    }
    return 0;
}
0