結果

問題 No.1140 EXPotentiaLLL!
ユーザー motmot
提出日時 2020-08-01 00:56:31
言語 C++11
(gcc 11.4.0)
結果
TLE  
実行時間 -
コード長 1,061 bytes
コンパイル時間 1,273 ms
コンパイル使用メモリ 83,632 KB
実行使用メモリ 14,652 KB
最終ジャッジ日時 2023-09-21 04:40:51
合計ジャッジ時間 8,327 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 TLE -
testcase_01 -- -
testcase_02 -- -
testcase_03 -- -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<cstring>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define rep(i, n) for(int i=0;i<n;++i)
#define rrep(i, n) for(int i=n;i>=0;--i)
const int inf=1e9+7;
const ll mod=1e9+7;
const ll big=1e18;
const double PI=2*asin(1);

int main() {
  int T;
  cin>>T;
  ll A, P;
  for(int j=0;j<T;++j) {
    cin>>A>>P;
    bool prime = true;
    if(P==1)  prime = false;
    for(ll i=2;i*i<=P;++i) {
      if(P%i==0) prime = false;
    }
    if(!prime) {
      cout<<-1<<endl;
      continue;
    }
    ll ans = 1;
    ll h;
    ll tmp, two;
    for(ll i=1;i<=P;++i) {
      h = i;
      while(h>0) {
        tmp = A;
        two = 1;
        while(2*two<h) {
          two *= 2;
          tmp *= tmp;
          tmp %= P;
        }
        h -= two;
        ans *= tmp;
        ans %= P;
      }
    }
    cout<<ans<<endl;
  }
}

0