結果

問題 No.1140 EXPotentiaLLL!
ユーザー hayatenhayaten
提出日時 2020-07-31 22:35:17
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,108 bytes
コンパイル時間 1,849 ms
コンパイル使用メモリ 164,784 KB
実行使用メモリ 4,504 KB
最終ジャッジ日時 2023-09-21 01:03:58
合計ジャッジ時間 19,237 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rrep(i, n) for (int i = (n - 1); i >= 0; i--)
#define ALL(v) v.begin(), v.end()
using namespace std;
using P = pair<int, int>;
typedef long long ll;

bool isPrime(int num) {
  if (num < 2) return false;
  else if (num == 2) return true;
  else if (num % 2 == 0) return false; // 偶数はあらかじめ除く
  double sqrtNum = sqrt(num);
  for (int i = 3; i <= sqrtNum; i += 2) {
    if (num % i == 0) {
      // 素数ではない
      return false;
    }
  }
  // 素数である
  return true;
}

long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

void solve() {
  ll a;
  int b;
  cin >> a >> b;
  if(!isPrime(b)){
    cout << -1 << endl;
    return;
  }
  if(a % b == 0){
    cout << 0 << endl;
    return;
  }
  ll sum = (1 + b) * b / 2;
  ll num = sum % (b - 1);
  cout << modpow(a, num, b) << endl;
}

int main(){
  int t;
  cin >> t;
  rep(i, t) solve();
}
0