Pagini recente » Cod sursa (job #1214902) | Cod sursa (job #1839456) | Cod sursa (job #1946927) | Cod sursa (job #1903313) | Cod sursa (job #2704870)
#include <bits/stdc++.h>
#define ll long long
using namespace std;
ifstream in("inversmodular.in");
ofstream out("inversmodular.out");
ll a, b, n, x, y;
void euclid(ll a, ll b, ll &x, ll &y) {
if (b == 0) {
x = 1;
y = 0;
return;
}
ll xx = x, yy = x;
euclid(b, a % b, xx, yy);
y = xx - (a / b) * yy;
x = yy;
}
int main() {
in >> a >> n;
euclid(a, n, x, y);
out << (x % n + n) % n;
return 0;
}