Pagini recente » Cod sursa (job #3293547) | Rating Damian Beles (damian_beles) | Asociatia infoarena | Cod sursa (job #3293796) | Cod sursa (job #3293004)
#include <bits/stdc++.h>
using namespace std;
ifstream fin("inversmodular.in");
ofstream fout("inversmodular.out");
void euclid(long long a, long long b, long long &d, long long &x, long long &y)
{
if(b == 0)
{
d = a;
x = 1;
y = 0;
}
else
{
long long x0, y0;
euclid(b, a % b, d, x0, y0);
x = y0;
y = x0 - (a / b) * y0;
}
}
int main()
{
long long a, b, d, x, y;
fin >> a >> b;
euclid(a, b, d, x, y);
if(x < 0)
x += b;
fout << x << "\n";
return 0;
}