Cod sursa(job #523363)

Utilizator PlayLikeNeverB4George Marcus PlayLikeNeverB4 Data 17 ianuarie 2011 21:27:34
Problema Invers modular Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.37 kb
#include <fstream>
using namespace std;
ifstream fin("inversmodular.in");
ofstream fout("inversmodular.out");

int A,N,x,y;

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

int main()
{
	fin >> A >> N;
	euclid(A,N,x,y);
	while(x<0) x+=N;
	fout << x;
}