Cod sursa(job #459008)

Utilizator R.A.RFMI Romila Remus Arthur R.A.R Data 27 mai 2010 16:59:54
Problema Invers modular Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.37 kb
#include <fstream>
using namespace std;
ifstream in("inversmodular.in");
ofstream out("inversmodular.out");
void ex(int a,int b,int &x, int &y)
{
	if(!b)
	{
		x=1;
		y=0;
	}
	else
	{
		int x0,y0;
		ex(b,a%b,x0,y0);
		x=y0;
		y = x0 -(a/b)*y0;
	}
}
int main ()
{
	int a,b;
	in>>a>>b;
	int x,y;
	ex(a,b,x,y);
	if(x<0)
		x+=b;
	out<<x;
	return 0;
}