結果

問題 No.1140 EXPotentiaLLL!
ユーザー hayatenhayaten
提出日時 2020-07-31 22:57:38
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,154 bytes
コンパイル時間 1,703 ms
コンパイル使用メモリ 165,580 KB
実行使用メモリ 11,760 KB
最終ジャッジ日時 2023-09-21 01:48:11
合計ジャッジ時間 13,754 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 1,231 ms
11,484 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 AC 39 ms
11,544 KB
testcase_09 AC 40 ms
11,652 KB
testcase_10 WA -
testcase_11 WA -
testcase_12 AC 40 ms
11,476 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;

const ll MAX_N = 5000000;
ll prime[MAX_N];
bool is_prime[MAX_N + 1];

//エラトステネスの篩
void sieve(ll n){
  ll p = 0;
  n = MAX_N;
  for (ll i = 0; i <= n; i++)
    is_prime[i] = true;
  is_prime[0] = is_prime[1] = false;
  for (ll i = 2; i <= n; i++){
    if(is_prime[i]){
      prime[p++] = i;
      for (ll j = 2 * i; j <= n; j += i)is_prime[j] = false;
    }
  }
}


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;
  ll p;
  cin >> a >> p;
  if(!is_prime[p]){
    cout << -1 << endl;
    return;
  }
  if(a % p == 0){
    cout << 0 << endl;
    return;
  }
  ll sum = (1 + p) * p / 2;
  ll num = sum % (p - 1);
  cout << modpow(a, num, p) << endl;
}

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