Cod sursa(job #2271988)
| Utilizator | Data | 29 octombrie 2018 16:04:50 | |
|---|---|---|---|
| Problema | Invers modular | Scor | 100 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva educationala | Marime | 0.51 kb |
#include <iostream>
#include <fstream>
using namespace std;
void gcd_extended(int a, int b, int &x, int &y)
{
if (!b)
{
x = 1;
y = 0;
return;
}
gcd_extended(b, a%b, x, y);
int aux = x;
x = y;
y = aux - (a / b) * x;
}
int main()
{
ifstream fin("inversmodular.in");
ofstream fout("inversmodular.out");
int a, n, x, y;
fin >> a >> n;
gcd_extended(a, n, x, y);
if (x < 0)
x += n;
fout << x;
return 0;
}
