Pagini recente » Cod sursa (job #2751421) | Cod sursa (job #1796639) | Profil M@2Te4i | Cod sursa (job #1856443) | Cod sursa (job #1248091)
#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);
fout << (m + a % m) % m << endl;
return 0;
}