Pagini recente » Cod sursa (job #2678940) | Cod sursa (job #1660869) | Cod sursa (job #778317) | Cod sursa (job #2099089) | Cod sursa (job #2845052)
#include <fstream>
void euclid_extins(int a, int b, int &x, int &y) {
if (b == 0) {
x = 1;
y = 0;
return;
}
int xx = x, yy = y;
euclid_extins(b, a % b, xx, yy);
x = yy;
y = xx - yy * (a / b);
}
int main() {
std::ifstream fin("inversmodular.in");
std::ofstream fout("inversmodular.out");
int a, n;
fin >> a >> n;
int x, y;
euclid_extins(a, n, x, y);
fout << (x + n) % n;
return 0;
}