Pagini recente » Cod sursa (job #2043453) | Cod sursa (job #1990415) | Cod sursa (job #375694) | Cod sursa (job #1868207) | Cod sursa (job #2594038)
#include<iostream>
#include<fstream>
#define LL long long
using namespace std;
int a,n;
void euclid_extins(LL &x,LL &y,int a,int b)
{
if(!b)
x = 1,y = 0;
else
{
euclid_extins( x, y, b, a%b);
LL aux = x;
x = y;
y = aux - y *(a / b);
}
}
int main()
{
ifstream cin("inversmodular.in");
ofstream cout("inversmodular.out");
LL inv = 0,ins;
cin>>a>>n;
euclid_extins(inv,ins,a,n);
if(inv <= 0)
inv = n +inv % n;
cout<<inv;
return 0;
}