Pagini recente » Cod sursa (job #1763172) | Cod sursa (job #1588367) | Cod sursa (job #737503) | Cod sursa (job #3219400) | Cod sursa (job #2470823)
#include <fstream>
using namespace std;
ifstream fin("inversmodular.in");
ofstream fout("inversmodular.out");
int euclext(unsigned long long a, unsigned long long b, unsigned long long c, unsigned long long &x, unsigned long long &y)
{
unsigned long long q[50], x0, y0, r, pos = 0;
while(b)
{
q[++pos] = a / b;
r = a % b;
a = b;
b = r;
}
if(c % a) {x=y=0;return 0;}
x0 = c / a;
y0 = 0;
while(pos)
{
x = y0;
y = x0 - q[pos--] * y0;
x0 = x;
y0 = y;
}
return 1;
}
int main()
{
unsigned long long a, b, x, y;
fin >> a >> b;
euclext(a, b, 1, x, y);
fout << x;
return 0;
}