Cod sursa(job #2038328)

Utilizator robuvedVictor Robu robuved Data 13 octombrie 2017 16:55:43
Problema Invers modular Scor 50
Compilator cpp Status done
Runda Arhiva educationala Marime 0.49 kb
#include <fstream>
using namespace std;

ifstream in("inversmodular.in");
ofstream out("inversmodular.out");
long long A, N;
long long EuclidExtins(long long a, long long b, long long&x, long long& y)
{
	if (b == 0)
	{
		x = 1;
		y = 0;
		return a;
	}
	long long x1, y1;
	long long r = EuclidExtins(b, a%b, x1, y1);

	x = y1;
	y = x1 - (a / b) * y1;

	return r;
}
int main()
{
	
	in >> A >> N;
	long long x, y;

	long long gcd = EuclidExtins(A, N, x, y);

	out << x;
}