結果

問題 No.1140 EXPotentiaLLL!
ユーザー akane
提出日時 2020-07-31 21:47:15
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
TLE  
実行時間 -
コード長 762 bytes
コンパイル時間 1,939 ms
コンパイル使用メモリ 193,684 KB
最終ジャッジ日時 2025-01-12 09:44:48
ジャッジサーバーID
(参考情報)
judge4 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other WA * 4 TLE * 8
権限があれば一括ダウンロードができます

ソースコード

diff #

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

int main(){
    int testcase; cin>> testcase;
    while(testcase--){
        ll A,P; cin>>A>>P;
        
        // Aが素数かどうか。
        bool pflg = false;
        if(A==1){
            cout << -1 << endl;
            pflg = true;
        }
        for(int i=2; i*i<A; i++){
            if(A%i==0){
                cout << -1 << endl;
                pflg = true;
            }
        }
        if(pflg) continue;

        // Aが素数の時
        ll rA=A;
        for(ll i=P; i>0; i--){
            for(ll j=0; j<P; j++){
                A *= rA;
                A %= P;
            }
        }
        cout << A << endl;
    }
}
0