Pagini recente » Istoria paginii runda/easy_choice | Cod sursa (job #2270843) | Istoria paginii utilizator/faithlambertac | Monitorul de evaluare | Cod sursa (job #2703079)
//#include <iostream>
#include <fstream>
using namespace std;
ifstream cin ("inversmodular.in");
ofstream cout ("inversmodular.out");
int gcd(int a, int b, int& x, int& y) {
if (b == 0) {
x = 1;
y = 0;
return a;
}
int x1, y1;
int d = gcd(b, a % b, x1, y1);
x = y1;
y = x1 - y1 * (a / b);
return d;
}
int main()
{
int a,n;
cin>>a>>n;
int x, y;
int g = gcd(a, n, x, y);
if(g==1)
{
x = (x % n + n) % n;
cout << x;
}
return 0;
}