Pagini recente » Cod sursa (job #1449285) | Cod sursa (job #36372) | Cod sursa (job #1508834) | Cod sursa (job #2561170) | Cod sursa (job #2742525)
#include <fstream>
using namespace std;
void euclid(int a, int b, int &x, int &y)
{
if (b == 0)
{
x = 1;
y = 0;
return;
}
int xx = x, yy = x;
euclid(b, a % b, xx, yy);
y = xx - (a / b) * yy;
x = yy;
}
int main()
{
ifstream fin("inversmodular.in");
ofstream fout("inversmodular.out");
int a, n, x, y;
fin >> a >> n;
euclid(a, n, x, y);
fout << (x % n + n) % n;
return 0;
}