Pagini recente » Cod sursa (job #1671247) | Cod sursa (job #1625553) | Cod sursa (job #2356165) | Cod sursa (job #2822717) | Cod sursa (job #2878574)
#include <fstream>
using namespace std;
ifstream cin("inversmodular.in");
ofstream cout("inversmodular.out");
void euclidth(long long &x, long long &y, int n, int mod)
{
if(!mod){
x = 1;
y = 1;
}
else{
euclidth(x, y, mod, n % mod);
long long aux = x;
x = y;
y = aux - y * (n / mod);
}
}
int main()
{
int a, mod;
cin >> a >> mod;
long long x, y;
euclidth(x, y, a, mod);
while(x < 0)
x += mod;
cout << x;
return 0;
}