結果

問題 No.1140 EXPotentiaLLL!
ユーザー misora192misora192
提出日時 2020-07-31 23:38:10
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 977 bytes
コンパイル時間 1,500 ms
コンパイル使用メモリ 166,364 KB
実行使用メモリ 15,864 KB
最終ジャッジ日時 2023-09-21 03:13:16
合計ジャッジ時間 7,483 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 219 ms
15,816 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 AC 39 ms
8,276 KB
testcase_09 AC 39 ms
8,156 KB
testcase_10 WA -
testcase_11 WA -
testcase_12 AC 40 ms
8,368 KB
権限があれば一括ダウンロードができます

ソースコード

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; }

bool isprime[5000001];

ll powmod(ll a, ll b, ll p){
	if(b == 0) return 1;
	if(b & 1) {
		return a * powmod(a, b - 1, p) % p;
	} else {
		ll d = powmod(a, b / 2, p) % p;
		return d * d % p;
	}
}

ll solve(ll a, ll p){
	if(!isprime[p]) return -1;
	ll ret = powmod(a, p, p);

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

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

	rep(i, 5000001) isprime[i] = true;
	isprime[0] = isprime[1] = false;
	for(int i = 2; i <= 5000000; i++){
		if(!isprime[i]) continue;
		for(int j = 2 * i; j <= 5000000; j += i) isprime[j] = 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