結果

問題 No.1140 EXPotentiaLLL!
コンテスト
ユーザー akane
提出日時 2020-07-31 21:47:15
言語 C++17
(gcc 15.2.0 + boost 1.89.0)
コンパイル:
g++-15 -O2 -lm -std=c++17 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
TLE  
実行時間 -
コード長 762 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 1,147 ms
コンパイル使用メモリ 209,408 KB
実行使用メモリ 9,600 KB
最終ジャッジ日時 2026-06-11 20:39:10
合計ジャッジ時間 8,554 ms
ジャッジサーバーID
(参考情報)
judge1_0 / judge2_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample -- * 1
other TLE * 1 -- * 11
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#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