Pagini recente » Ședință 2009-07-27 | Diferente pentru utilizator/harababurel intre reviziile 71 si 37 | Diferente pentru problema/poarta2 intre reviziile 5 si 3 | Diferente pentru problema/invazia intre reviziile 32 si 28 | Cod sursa (job #1800479)
#include <fstream>
using namespace std;
ifstream fin("inversmodular.in");
ofstream fout("inversmodular.out");
void gcdextins(long long a, long long b,long long &x, long long&y, long long d)
{
if(b==0)
{
d=a;
x=1;
y=0;
}
else
{
long long x0,y0,d0;
gcdextins(b,a%b,x0,y0,d0);
d=d0;
x=y0;
y=x0-(a/b)*y0;
}
}
long long a,n,x,y;
int main()
{
fin>>a>>n;
gcdextins(a,n,x,y,1);
if(x<0)
{
x=x+n;
}
fout<<x;
return 0;
}