Pagini recente » Cod sursa (job #1823436) | Cod sursa (job #951129) | Cod sursa (job #2556421) | Cod sursa (job #1764470) | Cod sursa (job #1413014)
#include <cstdio>
using namespace std;
int a,n;
void inversmodular(int a, int b, long long &x, long long &y)
{
if (b == 0)
{
x = 1;
y = 0;
return;
}
inversmodular(b,a%b,x,y);
int aux = x;
x = y;
y = aux - y * (a/b);
}
int main()
{
long long x=0,y=0;
freopen("inversmodular.in","r",stdin);
freopen("inversmodular.out","w",stdout);
scanf("%d%d",&a,&n);
inversmodular(a,n,x,y);
if (x > 0) printf("%lld\n",x);
else
{
x = n + x % n;
printf("%lld\n",x);
}
return 0;
}