Pagini recente » Cod sursa (job #657140) | Cod sursa (job #2547831) | Cod sursa (job #2208294) | Cod sursa (job #1773739) | Cod sursa (job #1608487)
#include <fstream>
using namespace std;
ifstream is("inversmodular.in");
ofstream os("inversmodular.out");
int a, n;
void EuclidE(long long & x, long long &y, int a, int n)
{
if(n == 0)
{
x = 1;
y = 0;
}
else
{
EuclidE(x, y, n, a%n);
long long aux = x;
x = y;
y = aux - y * (a/n);
}
}
int main()
{
is >> a >> n;
long long x = 0, y = 0;
EuclidE(x, y, a, n);
if(x <= 0)
x = n + x%n;
os << x;
is.close();
os.close();
return 0;
}