Pagini recente » Cod sursa (job #2442739) | Cod sursa (job #2376760) | Cod sursa (job #378109) | Cod sursa (job #747035) | Cod sursa (job #1414369)
#include <bits/stdc++.h>
using namespace std;
void gcd(int a, int b, int &x0, int &y0, int &d)
{
if (!b)
{
x0 = 1;
y0 = 0;
d = a;
}
else
{
int x, y;
gcd(b, a % b, x, y, d);
x0 = y;
y0 = x - (a / b) * y;
}
}
int main()
{
ifstream in("inversmodular.in");
ofstream out("inversmodular.out");
int a, b, d, x, y;
in >> a >> b;
gcd(a, b, x, y, d);
out << (x + b) % b << "\n";
return 0;
}