Pagini recente » Cod sursa (job #2953922) | Cod sursa (job #1382532) | Cod sursa (job #2390204) | Cod sursa (job #2662975) | Cod sursa (job #2900823)
#include <fstream>
using namespace std;
ifstream f("inversmodular.in");
ofstream g("inversmodular.out");
long long a, n, x, y;
void euclid(long long a, long long b, long long &x, long long &y)
{
if (b == 0) {
x = 1;
y = 1;
}
else {
euclid(b, a%b, x, y);
long long aux = y;
y = x - (a/b) * y;
x = aux;
}
}
int main()
{
f >> a >> n;
euclid(a, n, x, y);
x = x % n;
if (x < 0)
x += n;
g << x;
f.close();
g.close();
return 0;
}