Pagini recente » Cod sursa (job #524597) | Cod sursa (job #1643165) | Cod sursa (job #2120699) | Cod sursa (job #916168) | Cod sursa (job #2070407)
#include <fstream>
#include <iostream>
using namespace std;
ifstream f("inversmodular.in");
ofstream g("inversmodular.out");
long long n, a, x, y;
void euclid(long long a, long long b)
{
if(b == 0)
{
x = 1;
y = 0;
}
else
{
long long x0, y0;
euclid(b, a % b);
x0 = x;
y0 = y;
x = y0;
y = x0 - (a / b) * y0;
}
}
int main()
{
f >> a >> n;
euclid(a, n);
while(x < 0) x += n;
g << x << '\n';
return 0;
}