結果
問題 |
No.1140 EXPotentiaLLL!
|
ユーザー |
![]() |
提出日時 | 2020-07-31 21:30:09 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
TLE
|
実行時間 | - |
コード長 | 775 bytes |
コンパイル時間 | 1,367 ms |
コンパイル使用メモリ | 166,192 KB |
実行使用メモリ | 17,216 KB |
最終ジャッジ日時 | 2024-07-06 16:30:26 |
合計ジャッジ時間 | 8,561 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | -- * 1 |
other | TLE * 1 -- * 11 |
ソースコード
#include <bits/stdc++.h> using namespace std; typedef long long int ll; typedef pair<ll, ll> P; typedef vector<ll> VI; typedef vector<VI> VVI; const ll MOD = 1000000007; const ll INF = 1e18; #define REP(i, n) for(int i = 0; i < n; i++) #define ALL(v) v.begin(), v.end() ll power(ll x, ll y, ll p) { if (y==0) return 1; else if (y==1) return x%p; else if (y%2==0) { ll pow=power(x,y/2,p); return (pow*pow)%p; } else { ll pow=power(x,y/2,p); return ((pow*pow)%p)*x%p; } } int main() { int t; cin >> t; while(t--){ ll a, p; cin >> a >> p; bool no=0; for(int i=2;i<=sqrt(p);i++){ if(p%i==0){ printf("-1\n"); no=1; } } if(no) continue; ll f=0; for(int i=1;i<=p;i++){ f*=i; f%=(p-1); } printf("%ld\n",power(a,f,p)); } return 0; }