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