Cod sursa(job #544828)

Utilizator Ast09Stoica Anca Ast09 Data 2 martie 2011 11:03:39
Problema Invers modular Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.35 kb
#include<fstream.h>
ifstream F("inversmodular.in");
ofstream G("inversmodular.out");
long long x,y;
int A,B;

void f(long long &x, long long &y, int A,int B)
{if(B==0) x=1,y=0;
else { f(x,y,B,A%B);
	long long z=x;
	x=y;
	y=z-y*(A/B);
}
}
int main ()
{F>>A>>B;
f(x,y,A,B);
if(x<=0) x=B+x%B;
G<<x<<'\n';
F.close();
G.close();
return 0;
}