Cod sursa(job #2780227)
| Utilizator | Data | 6 octombrie 2021 15:16:02 | |
|---|---|---|---|
| Problema | Invers modular | Scor | 0 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva educationala | Marime | 0.43 kb |
#include<iostream>
using namespace std;
inline void gcd(int a, int b, int& x, int& y)
{
if (b == 0)
{
x = 1;
y = 0;
}
else
{
int x0, y0;
gcd(b, a % b, x0, y0);
x = y0;
y = x0 - (a / b) * y0;
}
}
int main()
{
freopen("inversmodular.in", "r", stdin);
freopen("inversmodular.out", "r", stdout);
int a, n;
cin >> a >> n;
int x, y;
gcd(a, n, x, y);
while (x < 0)
x += n;
cout << x;
}