Cod sursa(job #2721139)
| Utilizator | Data | 11 martie 2021 16:34:04 | |
|---|---|---|---|
| Problema | Invers modular | Scor | 90 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva educationala | Marime | 0.44 kb |
#include <iostream>
#include <fstream>
using namespace std;
ifstream fin("inversmodular.in");
ofstream fout("inversmodular.out");
int a, n, x, y;
int gcd_extins(int a, int b)
{ if(!b)
{ x = 1;
y = 0;
return a;
}
int gcd = gcd_extins(b, a % b), x1 = y, y1 = x - y * (a / b);
x = x1;
y = y1;
return gcd;
}
int main()
{
fin >> a >> n;
int gcd = gcd_extins(a, n);
fout << (x % n + n) % n << '\n';
return 0;
}