Pagini recente » Cod sursa (job #2701893) | Cod sursa (job #88154) | Cod sursa (job #2904781) | Cod sursa (job #1836707) | Cod sursa (job #1689641)
#include <fstream>
using namespace std;
ifstream f("inversmodular.in");
ofstream g("inversmodular.out");
int a, b, x, y;
int euclid(int a, int b, int &x, int &y)
{
if (b == 0)
{
x = 1;
y = 0;
return a;
}
else
{
int xx, yy;
euclid(b, a % b, xx, yy);
x = yy;
y = xx - (a / b) * yy;
}
}
int main()
{
f >> a >> b;
euclid(a, b, x, y);
while (x < 0)
x += b;
g << x << '\n';
return 0;
}