Cod sursa(job #2271749)

Utilizator Vlad_NituNitu Vlad-Petru Vlad_Nitu Data 29 octombrie 2018 10:28:17
Problema Invers modular Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.35 kb
#include <fstream>
#define ll long long
using namespace std;
ifstream f("inversmodular.in");
ofstream g("inversmodular.out");
ll a,n,inv,p;
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(inv,p,a,n);
if(inv<=0)inv=n+inv%n;
g<<inv;
return 0;
}