Pagini recente » Cod sursa (job #1086105) | Cod sursa (job #915192) | Cod sursa (job #2241003) | Sandbox (cutiuţa cu năsip) | Cod sursa (job #2883470)
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
void gcd(ll &x, ll &y, int a, int b) {
if (!b)
x = 1, y = 0;
else {
gcd(x, y, b, a % b);
ll aux = x;
x = y;
y = aux - y * (a / b);
}
}
int main() {
ifstream in("inversmodular.in");
ofstream out("inversmodular.out");
ll a, n, inv = 0, ins;
in >> a >> n;
gcd(inv, ins, a, n);
if (inv <= 0)
inv = n + inv % n;
out << inv;
return 0;
}