結果

問題 No.1140 EXPotentiaLLL!
ユーザー erbowlerbowl
提出日時 2021-01-30 06:42:25
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 864 bytes
コンパイル時間 2,384 ms
コンパイル使用メモリ 199,120 KB
実行使用メモリ 12,060 KB
最終ジャッジ日時 2023-09-09 23:39:25
合計ジャッジ時間 9,904 ms
ジャッジサーバーID
(参考情報)
judge11 / 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 #

typedef long long ll;
typedef long double ld;
#include <bits/stdc++.h>
using namespace std;
template< typename T >
T mod_pow(T x, T n, const T &p) {
  T ret = 1;
  while(n > 0) {
    if(n & 1) (ret *= x) %= p;
    (x *= x) %= p;
    n >>= 1;
  }
  return ret;
}
int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    ll t;
    std::cin >> t;
    for (int di = 0; di < t; di++) {
        ll a,p;
        std::cin >> a>>p;
        bool prime = false;
        for (int i = 2; i <= sqrt(p); i++) {
           if(p%i==0){
                prime = true;
                break;
            }
        }
        if(prime){
            if(a%p==0){
                std::cout << 0 << '\n';
                continue;
            }
            std::cout <<  mod_pow(a, p*(p+1)/2, p) << '\n';
        }else{
            std::cout << -1 << '\n';
        }
    }
}
0