Pagini recente » Cod sursa (job #1831166) | Cod sursa (job #2168206) | Cod sursa (job #1073991) | Cod sursa (job #2291288) | Cod sursa (job #823015)
Cod sursa(job #823015)
#include <iostream>
#include <fstream>
using namespace std;
void euclid_extins(long long a, long long b, long long *d, long long *x, long long *y)
{
if (b == 0)
{
*d = a;
*x = 1;
*y = 0;
}
else
{
long long x0, y0;
euclid_extins(b, a % b, d, &x0, &y0);
*x = y0;
*y = x0 - (a / b) * y0;
}
}
int main ()
{
long long A,N,d,x,y;
ifstream fi("inversmodular.in");
ofstream fo("inversmodular.out");
fi>>A>>N;
euclid_extins(A,N,&d,&x,&y);
while(x<0) x += N;
fo << x << "\n";
return 0;
}