Pagini recente » Cod sursa (job #1907043) | Cod sursa (job #1321112) | Cod sursa (job #2828024) | Cod sursa (job #3148478) | Cod sursa (job #2751139)
#include <bits/stdc++.h>
using namespace std;
ifstream fin("inversmodular.in");
ofstream fout("inversmodular.out");
int gcd(int a, int b, int &x, int &y) {
if(b == 0) {
x = 1;
y = 0;
return a;
}
int x0, y0;
int d = gcd(b, a % b, x0, y0);
x = y0;
y = x0 - y0 * (a / b);
return d;
}
int main() {
int A, N;
fin >> A >> N;
int x, y;
int d = gcd(A, N, x, y);
// if(d != 1) {
// cout << "test gresit!";
// return 0;
// }
fout << x << '\n';
return 0;
}