結果

問題 No.1140 EXPotentiaLLL!
ユーザー ぷらぷら
提出日時 2020-07-31 21:32:24
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 976 bytes
コンパイル時間 1,487 ms
コンパイル使用メモリ 166,352 KB
実行使用メモリ 50,920 KB
最終ジャッジ日時 2023-09-20 21:54:00
合計ジャッジ時間 8,812 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 #

#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int,int> P;
int INF = 1e16+7;
int mod = 1e9+7;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
int mod_pow(int x,int y,int MOD) {
    int res = 1;
    while(y > 0) {
        if(y%2) {
            res = res*x%MOD;
        }
        x = x*x%MOD;
        y/=2;
    }
    return res;
}
signed main() {
    vector<int>cnt(5000005,true);
    cnt[0] = cnt[1] = false;
    for(int i = 2; i <= 5000005; i++) {
        if(!cnt[i]) {
            continue;
        }
        for(int j = i*2; j <= 5000005; j+=i) {
            cnt[j] = false;
        }
    }
    int T;
    cin >> T;
    for(int i = 0; i < T; i++) {
        int A,P;
        cin >> A >> P;
        if(!cnt[P]) {
            cout << -1 << endl;
            continue;
        }
        int cnt = 1;
        for(int i = 2; i <= P; i++) {
            cnt*=i;
            cnt%=P;
        }
        cout << mod_pow(A,cnt,P) << endl;
    }
}
0