結果
問題 |
No.1140 EXPotentiaLLL!
|
ユーザー |
![]() |
提出日時 | 2020-07-31 22:31:28 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
TLE
|
実行時間 | - |
コード長 | 1,359 bytes |
コンパイル時間 | 1,974 ms |
コンパイル使用メモリ | 193,804 KB |
最終ジャッジ日時 | 2025-01-12 10:46:51 |
ジャッジサーバーID (参考情報) |
judge2 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 2 WA * 3 TLE * 7 |
ソースコード
#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; while(testcase--){ ll A,P; cin>>A>>P; mod = P; // Aが素数かどうか。 bool pflg = false; if(P<=2 || P%2==0){ cout << -1 << endl; pflg = true; }else{ for(int i=3; i*i<=P; i+=2){ if(P%i==0){ cout << -1 << endl; pflg = true; break; } } } cerr << P << endl; if(pflg) continue; // Pが素数の時 ll rA=A%P; ll ans = pow_kai(rA,(P-1)/2 + 1); // ll ans = (rA * rA)%mod; cout << ans << endl; // ll rA1 = pow_kai(rA,P); // cerr << rA1 << endl; // ll rA2 = pow_kai(rA,(P-1)/2); // cerr << rA2 << endl; // for(ll i=P; i>0; i--){ // rA = pow_kai(rA, i); // } } }