Pagini recente » Cod sursa (job #2004313) | Cod sursa (job #1569375) | Cod sursa (job #829056) | Cod sursa (job #3289984) | 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;
}