Cod sursa(job #500401)

Utilizator vlad_DVlad Dumitriu vlad_D Data 12 noiembrie 2010 03:46:07
Problema Invers modular Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.42 kb
#include <cstdio>

using namespace std;
typedef long long LL;
LL gcd(LL &x, LL &y, LL a, LL b) {
	if (b==0) {x=1; y=0; return a;}
	gcd(x, y, b, a % b);
	LL aux = x;
	x = y;
	y = aux - y * (a / b);
}
int main() {
	freopen("inversmodular.in", "r", stdin);
	freopen("inversmodular.out", "w", stdout);
	LL inv, inv2;
	LL A, N;
	scanf("%lld %lld", &A, &N);
	gcd(inv, inv2, A, N);
	inv = (N + inv) % N;
	printf("%lld\n", inv);
	return 0;
}