Cod sursa(job #902878)

Utilizator raulstoinStoin Raul raulstoin Data 1 martie 2013 17:09:17
Problema Invers modular Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.4 kb
#include <fstream>
#define LL long long
using namespace std;
inline void euclid(LL&x,LL&y,LL a,LL b)
{
	if(!b)
	{
		x=1;
		y=0;
		return;
	}
	LL X,Y;
	euclid(X,Y,b,a%b);
	x=Y;
	y=X-(a/b)*Y;
}
int main()
{
	LL x,y,a,b;
	ifstream fin("inversmodular.in");
	fin>>a>>b;
	fin.close();
	euclid(x,y,a,b);
	ofstream fout("inversmodular.out");
	fout<<(x%b+b)%b<<'\n';
	fout.close();
	return 0;
}