Pagini recente » Cod sursa (job #190429) | Cod sursa (job #2899004) | Cod sursa (job #1732117) | Cod sursa (job #802456) | Cod sursa (job #2673714)
#include <bits/stdc++.h>
using namespace std;
ifstream fin("inversmodular.in");
ofstream fout("inversmodular.out");
long long p,n,x1,y1;
void cmmdc(long long a,long long b,long long &x,long long &y)
{
if(b==0)
{
x=1;
y=0;
}
else
{
long long x0;
long long y0;
cmmdc(b,a%b,x0,y0);
x=y0;
y=x0-(a/b)*y0;
}
}
int main()
{
fin>>p>>n;
cmmdc(p,n,x1,y1);
if(x1<=0)x1=n+x1%n;
fout <<x1 << '\n';
return 0;
}