Pagini recente » Borderou de evaluare (job #2213395) | Borderou de evaluare (job #1837774) | Cod sursa (job #2721139)
#include <iostream>
#include <fstream>
using namespace std;
ifstream fin("inversmodular.in");
ofstream fout("inversmodular.out");
int a, n, x, y;
int gcd_extins(int a, int b)
{ if(!b)
{ x = 1;
y = 0;
return a;
}
int gcd = gcd_extins(b, a % b), x1 = y, y1 = x - y * (a / b);
x = x1;
y = y1;
return gcd;
}
int main()
{
fin >> a >> n;
int gcd = gcd_extins(a, n);
fout << (x % n + n) % n << '\n';
return 0;
}