Pagini recente » Cod sursa (job #1584957) | Cod sursa (job #847835) | Cod sursa (job #576978) | Cod sursa (job #2028023) | 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;
}