Pagini recente » Cod sursa (job #659178) | Cod sursa (job #2612346) | Cod sursa (job #671647) | Cod sursa (job #829442) | Cod sursa (job #1401841)
#include <fstream>
using namespace std;
ifstream cin("inversmodular.in");
ofstream cout("inversmodular.out");
int A,N;
long long inv=0,ins;
void gcd(long long &x, long long &y, int a, int b)
{
if(!b)
{
x=1;
y=0;
}
else
{
gcd(x,y,b,a%b);
long long aux=x;
x=y;
y=aux-y*(a/b);
}
}
int main()
{
cin>>A>>N;
gcd(inv,ins,A,N);
if(inv<=0)
inv=N+inv%N;
cout<<inv;
return 0;
}