Pagini recente » Cod sursa (job #273886) | Cod sursa (job #698869) | Istoria paginii runda/hardcore/clasament | Cod sursa (job #791344) | Cod sursa (job #791353)
Cod sursa(job #791353)
#include <fstream>
using namespace std;
void euclid(int a, int b, long long &x, long long &y)
{
if(!b)
x = 1, y = 0;
else
{
euclid(b, a % b, x, y);
long long aux = x;
x = y;
y = aux - y * (a / b);
}
}
int a, n;
int main()
{
long long x, y;
ifstream in("inversmodular.in"); ofstream out("inversmodular.out");
in>>a>>n;
euclid(a, n, x, y);
if(x < 0) x += n;
out<<x;
in.close(); out.close();
return 0;
}