Pagini recente » Cod sursa (job #15147) | Cod sursa (job #2153048) | Cod sursa (job #1125145) | Cod sursa (job #1303767) | Cod sursa (job #1248092)
#include <fstream>
using namespace std;
int gcd_ext(int a, int b, int &x, int &y) {
if (b == 0) {
x = 1;
y = 0;
return a;
}
int d = gcd_ext(b, a%b, x, y);
int t = x;
x = y;
y = t - (a / b) * y;
return d;
}
int main() {
ifstream fin("inversmodular.in");
ofstream fout("inversmodular.out");
int x, m, a, b;
fin >> x >> m;
gcd_ext(x, m, a, b);
long long r = a % m;
fout << (m + r) % m << endl;
return 0;
}