Pagini recente » Cod sursa (job #297096) | Cod sursa (job #679333) | Cod sursa (job #400807) | Cod sursa (job #2342366) | Cod sursa (job #1144596)
#include <iostream>
#include <stdio.h>
#define LL long long
using namespace std;
void euclid(LL a, LL b, LL &x, LL &y)
{
if (!b)
{
x=1;
y=0;
}
else
{
LL x0, y0;
euclid(b, a%b, x0, y0);
x=y0;
y=x0-(a/b)*y0;
}
}
void sol()
{
LL a, b, d, x, y;
scanf("%lld %lld", &a, &b);
euclid(a, b, x, y);
for (; x<0; x+=b);
printf("%d", x);
}
int main()
{
freopen("inversmodular.in", "r", stdin);
freopen("inversmodular.out", "w", stdout);
sol();
return 0;
}