Pagini recente » Istoria paginii runda/sim_oji_oni_tot | Cod sursa (job #1575675) | Istoria paginii runda/preoji2012 | Cod sursa (job #1129328) | 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;
}