sfh

turing_lisihan 2023-11-04 10:37:42

ahfl

共 1 条回复

turing_lisihan
#include <iostream>
using namespace std;
int q(long long a, long long b, long long p) {
	if (b==0) return 1;
	long long t=q(a, b/2, p);
	t=t*t%p;
	if (b%2==0) {
		return t;
	} else {
		return t*a%p;
	}
}
int main() {
	long long a, p;
	cin >> a >> p;
	if (a%p==0) cout << -1;
	else cout << q(a%p, p-2, p);
	return 0;
}