Pagini recente » Cod sursa (job #2717079) | Cod sursa (job #214728) | Cod sursa (job #1331930) | Cod sursa (job #2106563) | Cod sursa (job #1999367)
#include <fstream>
using namespace std;
int A,N,x,y,c,d;
int euclid(int a, int b, int &x, int &y){
if(b == 0){
x = 1;
y = 0;
return a;
}
int x0,y0;
d = euclid(b, a % b, x0, y0);
x = y0;
y = x0 - (a / b) * y0;
return d;
}
int main()
{
ifstream f("inversmodular.in");
ofstream g("inversmodular.out");
f >> A >> N;
///ax - qn = 1;
d = euclid(A,N,x,y);
x = x * (1/d);
if(x < 0)
x = N + x % N;
g << x;
return 0;
}