Pagini recente » Cod sursa (job #2758558) | Cod sursa (job #424217) | Cod sursa (job #2326197) | Cod sursa (job #2448403) | Cod sursa (job #2867238)
#include <fstream>
using namespace std;
ifstream fin("inversmodular.in");
ofstream fout("inversmodular.out");
int n, a, b, c;
int x, y;
int Euclid_E(int a, int b, int &x, int &y);
int main()
{
int aux;
fin>>a>>n;
Euclid_E(a, n, x, y);
if (x < 0) {
aux = (-1)*x;
aux/=n;
x+=(aux+1)*n;
}
fout<<x<<'\n';
return 0;
}
int Euclid_E(int a, int b, int &x, int &y) {
int x1, y1, d;
if (b == 0) {
x = 1; y = 0;
return a;
}
d = Euclid_E(b, a%b, x1, y1);
x = y1;
y = x1-y1*(a/b);
return d;
}