Pagini recente » Cod sursa (job #1857500) | Cod sursa (job #1499534) | Cod sursa (job #3251628) | Cod sursa (job #780858) | Cod sursa (job #2393815)
#include <bits/stdc++.h>
using namespace std;
int A, N;
void modularinverse(long long &x, long long &y, int a, int b)
{
if (b == 0)
{
x = 1;
y = 0;
return;
}
modularinverse(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;
modularinverse(x, y, A, N);
if (x <= 0)
x = N + x % N;
printf("%lld", x);
return 0;
}