Pagini recente » Cod sursa (job #2721766) | Cod sursa (job #2299848) | Cod sursa (job #3236990) | Cod sursa (job #1832158) | Cod sursa (job #2606386)
#include <fstream>
using namespace std;
ifstream in("inversmodular.in");
ofstream out("inversmodular.out");
void euclid_e( int a, int b, int& x, int& y, int& d ) {
if ( b == 0 )
{
d = a;
x = 1;
y = 0;
return;
}
int xx, yy, q = a / b;
euclid_e( b, a % b, xx, yy, d );
x = yy;
y = xx - yy * q;
}
int main()
{
int a, n, x, y, d;
in >> a >> n;
euclid_e(a, n, x, y, d);
x %= n;
if (x < 0)
{
x += n;
}
out << x;
in.close();
out.close();
return 0;
}