Pagini recente » Monitorul de evaluare | Monitorul de evaluare | Borderou de evaluare (job #3357859) | Monitorul de evaluare | Cod sursa (job #3357862)
#include <fstream>
using namespace std;
ifstream cin("inversmodular.in");
ofstream cout("inversmodular.out");
void euclid_extins(int a, int b, int &x, int &y) {
if (b == 0) {
x = 1;
y = 0;
return;
}
euclid_extins(b, a % b, x, y);
int aux = x;
x = y;
y = aux - (a / b) * y;
}
int main() {
int a, n;
cin >> a >> n;
int x, y;
euclid_extins(a, n, x, y);
x %= n;
if (x < 0) x += n;
cout << x;
return 0;
}