Pagini recente » Cod sursa (job #1585638) | Cod sursa (job #1699642) | Cod sursa (job #2886054) | Cod sursa (job #2064259) | 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;
}