Pagini recente » Cod sursa (job #423754) | Cod sursa (job #1848250) | Cod sursa (job #750493) | Cod sursa (job #553278) | Cod sursa (job #1414641)
#include <cstdio>
using namespace std;
int x , mod;
long long inv , ins;
void gcd(long long &x , long long &y , int a , int b)
{
if (!b)
x = 1 , y = 0;
else
{
gcd(x , y , b , a % b);
long long aux = x;
x = y;
y = aux - y * (a / b);
}
}
int main()
{
freopen("inversmodular.in","r",stdin);
freopen("inversmodular.out","w",stdout);
scanf("%d %d", &x, &mod);
gcd(inv , ins , x , mod);
if (inv <= 0) inv = mod + inv % mod;
printf("%lld\n", inv);
return 0;
}