結果

問題 No.1140 EXPotentiaLLL!
ユーザー misora192
提出日時 2020-07-31 23:29:28
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
TLE  
実行時間 -
コード長 669 bytes
コンパイル時間 1,327 ms
コンパイル使用メモリ 168,812 KB
実行使用メモリ 24,892 KB
最終ジャッジ日時 2024-07-06 21:42:29
合計ジャッジ時間 8,479 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample -- * 1
other TLE * 1 -- * 11
権限があれば一括ダウンロードができます

ソースコード

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