Pagini recente » Cod sursa (job #1539872) | Cod sursa (job #1071912) | Cod sursa (job #2421543) | Diferente pentru problema/3dist intre reviziile 6 si 4 | Cod sursa (job #2175036)
#include <fstream>
using namespace std;
ifstream fin("inversmodular.in");
ofstream fout("inversmodular.out");
void gcd(int a,int b,long long &x,long long &y)
{
if(!b)
{
x=1;
y=0;
}
else
{
gcd(b,a%b,x,y);
int au=x;
x=y;
y=au-(a/b)*y;
}
}
int main()
{
long long x=0,y;
int n,p;
fin>>n>>p;
gcd(n,p,x,y);
if(x<0)
x=x+x%p;
fout<<x;
}