Cod sursa(job #1166643)

Utilizator Dddarius95Darius-Florentin Neatu Dddarius95 Data 3 aprilie 2014 18:48:12
Problema Invers modular Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.48 kb
//Invers modular - log(N)

#include <fstream>
#define LL long long
using namespace std;
ifstream f("inversmodular.in");
ofstream g("inversmodular.out");

LL N,A,X,Y;

LL gcd(LL a,LL b,LL &x,LL &y)
{
     if(!b){x=1,y=0;return a;}
     LL  x0,y0,D;
     D=gcd(b,a % b, x0,y0);
     x=y0;
     y=x0-(a/b)*y0;
     return D;
}


int main()
{
     LL A,N,inv,ins;
     f>>A>>N;
     gcd(A,N,inv,ins);
     while(inv<=0)inv+=N;
     g<<inv<<'\n';
     return 0;
}