Pagini recente » Cod sursa (job #292202) | Cod sursa (job #2882209) | Cod sursa (job #2573) | Cod sursa (job #1604367) | Cod sursa (job #2795400)
#include <iostream>
#include <fstream>
using namespace std;
ifstream fin("inversmodular.in");
ofstream fout("inversmodular.out");
int a, n;
void euclid(int a, int b, int &x, int &y)
{
if (!b) {
x = 1;
y = 0;
return;
}
int x0, y0;
euclid(b, a % b, x0, y0);
x = y0;
y = x0 - (a / b) * y0;
}
int main()
{
fin >> a >> n;
int x, y;
euclid(a, n, x, y);
fout << (x >= 0 ? x : (x + n) % n);
fin.close();
fout.close();
return 0;
}