Pagini recente » Cod sursa (job #3190024) | Cod sursa (job #164657) | Cod sursa (job #3145926) | Cod sursa (job #1632200) | Cod sursa (job #2645610)
/**
* author: etohirse
* created: 29.08.2020 09:33:18
**/
#include <fstream>
using ll = long long;
std::ifstream fin("inversmodular.in");
std::ofstream fout("inversmodular.out");
int a, n;
void ecl(ll &x, ll &y, int a, int b) {
if (!b) {
x = 1, y = 0;
} else {
ecl(x, y, b, a % b);
ll aux = x;
x = y;
y = aux - y * (a / b);
}
}
int main() {
ll inv = 0, ins;
fin >> a >> n;
ecl(inv, ins, a, n);
if (inv <= 0) {
inv = n + inv % n;
}
fout << inv;
return 0;
}