Pagini recente » Cod sursa (job #44068) | Cod sursa (job #2751255) | Cod sursa (job #753529) | Cod sursa (job #961303) | Cod sursa (job #2422466)
#include <bits/stdc++.h>
#define lld long long
using namespace std;
// in x se va gasi inversul modular al lui a, Zb
lld invMod(lld &x, lld &y, int a, int b)
{
if (!b)
x = 1, y = 0;
else
{
invMod(x, y, b, a%b);
lld aux = x;
x = y;
y = aux - y*(a/b);
}
}
lld x, y;
int a, b;
int main()
{
freopen("inversmodular.in","r",stdin);
freopen("inversmodular.out","w",stdout);
cin>>a>>b;
invMod(x,y,a,b);
if (x < 0) x = b + x;
cout<<x<<'\n';
return 0;
}