結果
問題 |
No.1140 EXPotentiaLLL!
|
ユーザー |
![]() |
提出日時 | 2020-07-31 22:25:32 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,355 bytes |
コンパイル時間 | 4,131 ms |
コンパイル使用メモリ | 191,696 KB |
最終ジャッジ日時 | 2025-01-12 10:38:54 |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | WA * 1 |
other | WA * 12 |
ソースコード
#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){ // 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; // } // } // } 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); // } } }