Cod sursa(job #1060892)

Utilizator federerUAIC-Padurariu-Cristian federer Data 18 decembrie 2013 21:11:54
Problema Invers modular Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.44 kb
#include<fstream>
using namespace std;

ifstream fin("inversmodular.in");
ofstream fout("inversmodular.out");

void euclid_ext(int a, int b, int &x, int &y)
{
	if (b == 0)
	{
		x = 1;
		y = 0;
	}
	else
	{
		int x0, y0;
		euclid_ext(b, a%b, x0, y0);
		x = y0;
		y = x0 - (a / b)*y0;
	}

}

int main()
{
	int A, N, x, y;
	
	fin >> A >> N;
	euclid_ext(A, N, x, y);
	if (x < 0)
		x = (x + N)%N;
	fout<<x<<'\n';
	return 0;
}