Pagini recente » Cod sursa (job #1970958) | Cod sursa (job #2209026) | Cod sursa (job #2587756) | Cod sursa (job #2622795) | Cod sursa (job #1181405)
#include <iostream>
#include <fstream>
using namespace std;
void gcd(long long &x, long long &y, long long a,long long b)
{
if(b==0)
{
x=1;
y=0;
}
else
{
gcd(x,y,b,a%b);
long long aux=x;
x=y;
y=aux-y*(a/b);
}
}
int main()
{
ifstream fin("inversmodular.in");
ofstream fout("inversmodular.out");
long long a,n,x,y;
fin>>a>>n;
gcd(x,y,a,n);
if(x<0)
x=n+x%n;
fout<<x;
return 0;
}