Pagini recente » Cod sursa (job #788963) | Cod sursa (job #2943792) | Cod sursa (job #1806018) | Cod sursa (job #443576) | Cod sursa (job #2703080)
//#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()
{
long long a,n;
cin>>a>>n;
long long x, y;
long long g = gcd(a, n, x, y);
if(g==1)
{
x = (x % n + n) % n;
cout << x;
}
return 0;
}