Cod sursa(job #3180902)
Utilizator | Data | 6 decembrie 2023 09:30:55 | |
---|---|---|---|
Problema | Invers modular | Scor | 100 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva educationala | Marime | 0.45 kb |
#include <bits/stdc++.h>
#define ll int64_t
using namespace std;
ifstream f("inversmodular.in");
ofstream g("inversmodular.out");
ll a,n,x,y;
ll cmmdc(ll a,ll b,ll &x,ll &y)
{
if(b==0)
{
x=1;
y=0;
return a;
}
ll X,Y,D;
cmmdc(b,a%b,X,Y);
x=Y;
y=X-a/b*Y;
return D;
}
int main()
{
f>>a>>n;
cmmdc(a,n,x,y);
x%=n;
while(x<0)
x+=n;
g<<x;
return 0;
}