Pagini recente » Cod sursa (job #374248) | Cod sursa (job #1737359) | Cod sursa (job #1473332) | Cod sursa (job #1391591) | Cod sursa (job #2000351)
// Algoritmul lui Euclid extins
#include<bits/stdc++.h>
using namespace std;
ifstream f("invm.in");
ofstream g("invm.out");
int a,b,c,d,t,x,y;
void euclid(int a, int b, int &d, int &x, int &y)
{
if (b == 0){
d = a;
x = 1;
y = 0;
}
else
{
int x0, y0;
euclid(b, a % b, d, x0, y0);
x = y0;
y = x0 - (a / b) * y0;
}
}
int main()
{
f>>a>>b;
euclid(a,b,d,x,y);
if(x<0)
x=x+(b/x)*x;
g<<x;
return 0;
}