Pagini recente » Cod sursa (job #3265154) | Cod sursa (job #2978593) | Cod sursa (job #1482706) | Cod sursa (job #3156286) | Cod sursa (job #3030303)
#include <fstream>
#define int long long
using namespace std;
ifstream cin ("inversmodular.in");
ofstream cout ("inversmodular.out");
void euclid(int a,int b,int &x,int &y)
{
if (b==0)
{
x = 1;
y = 0;
return;
}
int x0,y0;
euclid(b,a%b,x0,y0);
x = y0;
y = x0 - (a/b)*y0;
}
int32_t main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int nr,n;
cin >> nr >> n;
int x,y;
euclid(nr,n,x,y);
while (x<0)
x = x + n;
cout << x;
return 0;
}