結果

問題 No.1140 EXPotentiaLLL!
ユーザー misora192misora192
提出日時 2020-07-31 23:29:28
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 669 bytes
コンパイル時間 1,529 ms
コンパイル使用メモリ 167,112 KB
実行使用メモリ 19,832 KB
最終ジャッジ日時 2023-09-21 03:02:33
合計ジャッジ時間 8,734 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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>
#define rep(i,n) for(int i=(0);i<(n);i++)

using namespace std;

typedef long long ll;

template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }

const ll MOD = 1e9 + 7;

ll solve(ll a, ll p){
	for(int i = 2; i * i <= p; i++){
		if(p % i == 0) return -1;
	}

	ll ret = 1ll;
	rep(i, p) {
		ret *= a;
		a %= p;
	}

	return ret * (p - 1) % p;
}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);

	ll t;
	cin >> t;

	vector<ll> a(t), p(t);
	rep(i, t) cin >> a[i] >> p[i];

	rep(i, t) cout << solve(a[i], p[i]) << "\n";
}
0