Pagini recente » Cod sursa (job #8801) | Cod sursa (job #2714080) | Cod sursa (job #1039273) | Cod sursa (job #1234470) | Cod sursa (job #2520506)
#include <fstream>
#define LL long long
using namespace std;
ifstream fin("inversmodular.in");
ofstream fout("inversmodular.out");
int T,x,y,A,N;
LL a,b,L,inv,p;
void cmmdc(int a,int b,LL &x,LL &y)
{
if(!b)
{
x=1;
y=0;
}
else
{
cmmdc(b,a%b,x,y);
LL aux=x;
x=y;
y=aux-y*(a/b);
}
}
int main()
{
fin>>A>>N;
cmmdc(A,N,inv,p);
if(inv<=0)
inv=N+inv%N;
fout<<inv;
return 0;
}