Pagini recente » Cod sursa (job #904643) | Cod sursa (job #2845766) | Cod sursa (job #2539614) | Cod sursa (job #2227987) | Cod sursa (job #1098930)
#include <fstream>
using namespace std;
ifstream fin ("inversmodular.in");
ofstream fout ("inversmodular.out");
int n;
int Euclid(int, int, int&, int&);
int main()
{
int a, b;
int x, y;
fin>> a>> b;
Euclid (a, b, x, y);
while (x<0) x=x+b;
fout<< x<< "\n";
fin.close();
fout.close();
return 0;
}
int Euclid (int a, int b, int& x, int& y)
{
int x0, y0, val;
if (b==0) {x=1; y=0; return a;}
val = Euclid(b, a%b, x0, y0);
x=y0;
y=x0-y0*(a/b);
return val;
}