Cod sursa(job #2050415)

Utilizator aditzu7Adrian Capraru aditzu7 Data 28 octombrie 2017 09:50:05
Problema Invers modular Scor 50
Compilator cpp Status done
Runda Arhiva educationala Marime 0.36 kb
#include <fstream>
#define ll unsigned long long
using namespace std;
ifstream f("inversmodular.in");
ofstream g("inversmodular.out");
ll x,y,a,n;
void gcd(ll &x,ll &y,ll a,ll b){
if(b==0) {x=1;y=0;}
else{gcd(x,y,b,a%b);
    ll aux=x;
    x=y;
    y=aux-y*(a/b);
}

}
int main()
{
   f>>a>>n;
gcd(x,y,a,n);
if(x<0) x=n+x%n;
g<<x;
    return 0;
}