Cod sursa(job #2673714)
Utilizator | Andrei Bazavan andreibazavan | Data | 17 noiembrie 2020 16:14:09 |
---|---|---|---|
Problema | Invers modular | Scor | 0 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva educationala | Marime | 0.52 kb |
#include <bits/stdc++.h>
using namespace std;
ifstream fin("inversmodular.in");
ofstream fout("inversmodular.out");
long long p,n,x1,y1;
void cmmdc(long long a,long long b,long long &x,long long &y)
{
if(b==0)
{
x=1;
y=0;
}
else
{
long long x0;
long long y0;
cmmdc(b,a%b,x0,y0);
x=y0;
y=x0-(a/b)*y0;
}
}
int main()
{
fin>>p>>n;
cmmdc(p,n,x1,y1);
if(x1<=0)x1=n+x1%n;
fout <<x1 << '\n';
return 0;
}