Pagini recente » Cod sursa (job #3316799) | Cod sursa (job #887973) | Cod sursa (job #3338428) | Cod sursa (job #2963498) | Cod sursa (job #3339624)
#include <iostream>
#include <fstream>
using namespace std;
ifstream fin("inversmodular.in");
ofstream fout("inversmodular.out");
int a,b,x,y,d;
void euclid(int a, int b, int &x, int &y,int &d)
{
if(b==0)
{
d=a;
x=1;
y=0;
}
else
{
int x0,y0;
euclid(b, a%b, x0,y0,d);
x=y0;
y=x0-(a/b)*y0;
}
}
int main()
{
fin>>a>>b;
euclid(a,b,x,y,d);
while(x<0)
{
x+=b;
}
fout<<x;
return 0;
}