Cod sursa(job #841595)

Utilizator SebiSebiPirtoaca George Sebastian SebiSebi Data 24 decembrie 2012 14:35:12
Problema Invers modular Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.42 kb
#include<iostream>
#include<fstream>
using namespace std;

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

int main ()
{
	int a,n,x,y;
	ifstream f("inversmodular.in");
	ofstream g("inversmodular.out");
	f>>a>>n;
	f.close();
	gcd(a,n,x,y);
	while(x<=0) 
		x=n+x%n;
	g<<x;
	g.close();
	return 0;
}