Pagini recente » Cod sursa (job #2637344) | Cod sursa (job #1614701) | Cod sursa (job #72118) | Cod sursa (job #2581020) | 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;
}