結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1,233 ms
11,456 KB
testcase_01 AC 1,204 ms
11,672 KB
testcase_02 AC 1,222 ms
11,532 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 AC 38 ms
11,532 KB
testcase_09 AC 39 ms
11,496 KB
testcase_10 WA -
testcase_11 WA -
testcase_12 AC 41 ms
11,488 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 (int i = 0; i <= n; i++)
    is_prime[i] = true;
  is_prime[0] = is_prime[1] = false;
  for (int i = 2; i <= n; i++){
    if(is_prime[i]){
      prime[p++] = i;
      for (int 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;
  int 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) % p << endl;
}

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