Cod sursa(job #841592)

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

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

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