Pagini recente » Cod sursa (job #1139937) | Cod sursa (job #3173053) | Cod sursa (job #1965095) | Cod sursa (job #1037632) | Cod sursa (job #1920871)
#include <fstream>
using namespace std;
ifstream f("inversmodular.in");
ofstream g("inversmodular.out");
int n, m, x, y;
int euclid(int n, int m, int &x, int &y)
{
if (m == 0)
{
x = 1;
y = 0;
return n;
}
else
{
int xx, yy;
euclid(m, n % m, xx, yy);
x = yy;
y = xx - (n / m) * yy;
}
}
int main()
{
f >> n >> m;
euclid(n, m, x, y);
while (x < 0)
x += m;
g << x;
return 0;
}