Cod sursa(job #716827)

Utilizator romircea2010FMI Trifan Mircea Mihai romircea2010 Data 19 martie 2012 12:12:42
Problema Invers modular Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.45 kb
#include <fstream>

using namespace std;

int A, N;

void Euclid_Extins(long long &x, long long &y, int a, int b)
{
	if (!b)
	{
		x = 1;
		y = 0;
	}
	else
	{
		Euclid_Extins(x, y, b, a%b);
		long long aux = x;
		x = y;
		y = aux - y*(a/b);
	}
}

int main()
{
	ifstream f("inversmodular.in");
	ofstream g("inversmodular.out");
	f>>A>>N;
	f.close();
	long long x, y;
	Euclid_Extins(x, y, A, N);
	if (x<=0)
		x = N + x%N;
	g<<x<<"\n";
	g.close();
	return 0;
}