Pagini recente » Cod sursa (job #570412) | Cod sursa (job #1404558) | Cod sursa (job #3132557) | Cod sursa (job #965241) | Cod sursa (job #3329539)
#include <bits/stdc++.h>
#include <fstream>
using namespace std;
ifstream fin("inversmodular.in");
ofstream fout("inversmodular.out");
void gcd(long long &x, long long &y, long long a, long long b) {
if (b == 0) {
x = 1;
y = 0;
} else {
gcd(x, y, b, a % b);
long long aux = x;
x = y;
y = aux - y * (a / b);
}
}
int main() {
long long a, n, inv = 0, ins = 0;
fin >> a >> n;
gcd(inv, ins, a, n);
inv = (inv % n + n) % n;
fout << inv;
}