Pagini recente » Cod sursa (job #193356) | Cod sursa (job #1368614) | Cod sursa (job #1476906) | Cod sursa (job #97036) | Cod sursa (job #1275839)
#include <fstream>
using namespace std;
ifstream f("inversmodular.in");
ofstream g("inversmodular.out");
int a,n,x,y,d;
int euclid(int a,int b,int &x,int &y)
{
int xp=0,yp=0,d=0;
if(b==0)
{
x=1;
y=0;
return a;
}
else
{
d=euclid(b,a%b,xp,yp);
x=yp;
y=xp-(a/b)*yp;
return d;
}
}
int main()
{
f>>a>>n;
d=euclid(a,n,x,y);
if(x>0)
g<<x;
else
{
while(x<=0)
x=x+n;
g<<x;
}
return 0;
}