結果

問題 No.1140 EXPotentiaLLL!
ユーザー HaaHaa
提出日時 2020-07-31 21:30:09
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 775 bytes
コンパイル時間 1,361 ms
コンパイル使用メモリ 164,764 KB
実行使用メモリ 12,208 KB
最終ジャッジ日時 2023-09-20 21:43:35
合計ジャッジ時間 8,517 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 <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;
}
0