Pagini recente » Cod sursa (job #479174) | Cod sursa (job #1006455) | Cod sursa (job #714132) | Cod sursa (job #1005699) | Cod sursa (job #1369524)
#include <algorithm>
#include <fstream>
#include <iostream>
using namespace std;
ifstream fin("inversmodular.in");
ofstream fout("inversmodular.out");
int euclid(int a, int b, int &x, int &y) {
if (b == 0) {
x = 1;
y = 0;
return a;
}
int d = euclid(b, a % b, x, y);
int xp = x, yp = y;
x = yp;
y = xp - (a / b) * yp;
return d;
}
int main() {
int a, n;
fin >> a >> n;
int x, y;
euclid(a, n, x, y);
fout << x;
return 0;
}