結果

問題 No.1140 EXPotentiaLLL!
ユーザー akaneakane
提出日時 2020-07-31 22:51:17
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,177 bytes
コンパイル時間 2,304 ms
コンパイル使用メモリ 205,180 KB
実行使用メモリ 58,824 KB
最終ジャッジ日時 2023-09-21 01:33:21
合計ジャッジ時間 23,413 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i,n) for (int i=0; i < (n); i++)
using namespace std;
using ll = long long;

ll mod;

ll pow_kai(ll a, ll n){//aのn乗を計算します。
  ll x = 1;
  while(n > 0){//全てのbitが捨てられるまで。
    if(n&1){//1番右のbitが1のとき。
      x = x*a;
      x %= mod;
    }
    a = a*a;
    a %= mod;
    n >>= 1;//bit全体を右に1つシフトして一番右を捨てる。
  }
  return x;
}

int main(){
    int testcase; cin>> testcase;
    vector<ll> vp(5000000+1,0);
    set<ll> prime;
    for(int i=2; i*i<=5000000; i++){
        ll x=i+i;
        while(x<=5000000){
            vp[x]=1;
            x += i;
        }
    }
    for(int i=2; i<vp.size(); i++){
        if(vp[i]==0){
            prime.insert(i);
        }
    }

    while(testcase--){
        ll A,P; cin>>A>>P;
        mod = P;
        // Aが素数かどうか。
        bool pflg = false;
        if(prime.count(P)){
          pflg=true;
        }else{
          cout << -1 << endl;
          continue;
        }

        // Pが素数の時
        ll rA=A%P;
        ll ans = pow_kai(rA,(P-1)/2 + 1)%mod;
        cout << ans << endl;

    }
}
0