Pagini recente » Cod sursa (job #725846) | Cod sursa (job #1298976) | Cod sursa (job #1247461) | Cod sursa (job #368064) | Cod sursa (job #1348566)
#include <cstdio>
long long s1 , s2;
int a, m;
void euclid (long long &x, long long &y, int a, int b)
{
if (b==0)
{
x = 1;
y = 0;
}
else
{
long long d;
euclid(x, y, b, a % b);
d= x;
x = y;
y = d - y * (a / b);
}
}
int main()
{
freopen("inversmodular.in", "r", stdin);
freopen("inversmodular.out", "w", stdout);
scanf("%d %d", &a, &m);
euclid(s1, s2, a, m);
if (s1 <= 0)
s1 = m + s1 % m;
printf("%d\n", s1);
return 0;
}