Cod sursa(job #2742525)
Utilizator | Data | 21 aprilie 2021 09:54:48 | |
---|---|---|---|
Problema | Invers modular | Scor | 90 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva educationala | Marime | 0.47 kb |
#include <fstream>
using namespace std;
void euclid(int a, int b, int &x, int &y)
{
if (b == 0)
{
x = 1;
y = 0;
return;
}
int xx = x, yy = x;
euclid(b, a % b, xx, yy);
y = xx - (a / b) * yy;
x = yy;
}
int main()
{
ifstream fin("inversmodular.in");
ofstream fout("inversmodular.out");
int a, n, x, y;
fin >> a >> n;
euclid(a, n, x, y);
fout << (x % n + n) % n;
return 0;
}