Pagini recente » Cod sursa (job #2690192) | Cod sursa (job #2002789) | Cod sursa (job #2077643) | Cod sursa (job #1886918) | Cod sursa (job #2017254)
#include <iostream>
#include <cstdio>
using namespace std;
int a, n;
void findX(long long &x, long long &y, int a, int b)
{
if(b == 0){
x = 1;
y = 0;
return ;
}
findX(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", &a, &n);
long long x=0, y=0;
findX(x, y, a, n);
if(x <= 0)
x = n + x%n;
printf("%lld", x);
return 0;
}