Pagini recente » Cod sursa (job #2840508) | Cod sursa (job #1423636) | Cod sursa (job #436437) | Cod sursa (job #2144350) | Cod sursa (job #1610571)
#include <fstream>
using namespace std;
ifstream fin("inversmodular.in");
ofstream fout("inversmodular.out");
int euclid(int a, int b, int &x, int &y);
int main()
{
int a, n, x, y, d;
fin >> a >> n;
d = euclid(a, n, x, y);
while (x < 0)
x += n;
fout << x << '\n';
return 0;
}
int euclid(int a, int b, int &x, int &y)
{
int x1, y1;
if (!b)
{
x = 1;
y = 0;
return a;
}
else
{
euclid(b, a % b, x1, y1);
x = y1;
y = x1 - (a / b) * y1;
}
}