Cod sursa(job #544823)

Utilizator andrei.finaruFinaru Andrei Emanuel andrei.finaru Data 2 martie 2011 10:52:57
Problema Invers modular Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.36 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; 
	
}