Cod sursa(job #662946)

Utilizator razielreaperMatei Andrei razielreaper Data 17 ianuarie 2012 14:08:49
Problema Invers modular Scor 0
Compilator cpp Status done
Runda Arhiva educationala Marime 0.44 kb
#include<fstream>
#include<algorithm>
#include<math>
using namespace std;
long  a,b,d,x,y,z,n,i;
void aeuclid(long a,long b,long z,long &x,long &y)
{
	long  x0,y0;
	if (b==0){
		z=a;
		x=1;
		y=0;
	}
	else {
		aeuclid(b,a%b,z,x0,y0);
		x=y0;
		y = x0 - (a / b) * y0;
	}
}
		
int main(){
	ifstream f("inversmodular.in");
	ofstream g("inversmodular.out");
	f>>a>>n;
	aeuclid(a,n,1,x,y);
	while (x<0)
		x=x+n;
	g<<x;
	return 0;
}