Pagini recente » Cod sursa (job #1000873) | Cod sursa (job #796291) | Cod sursa (job #494359) | Cod sursa (job #223248) | Cod sursa (job #2257713)
#include <fstream>
using namespace std;
using ll = long long;
ifstream fin("inversmodular.in");
ofstream fout("inversmodular.out");
void gcd(ll &x, ll &y, ll a, ll 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()
{
int a, n;
ll inv = 0, ins;
fin >> a >> n;
gcd(inv, ins, a, n);
if (inv <= 0)
inv = n + inv % n;
fout << inv << '\n';
return 0;
}