Cod sursa(job #2745563)
Utilizator | Data | 26 aprilie 2021 19:06:00 | |
---|---|---|---|
Problema | Invers modular | Scor | 100 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva educationala | Marime | 0.52 kb |
#include <fstream>
using namespace std;
void euclid(long long a, long long b, long long &x, long long &y, long long &d)
{
if (b == 0)
{
d = a;
x = 1;
y = 0;
return;
}
long long xx, yy, q = a / b;
euclid(b, a % b, xx, yy, d);
x = yy;
y = xx - yy * q;
}
int main()
{
ifstream cin("inversmodular.in");
ofstream cout("inversmodular.out");
long long a,n,x,y,d;
cin>>a>>n;
euclid(a,n,x,y,d);
cout<<(n+x%n)%n;
return 0;
}