Pagini recente » Cod sursa (job #448458) | Cod sursa (job #86347) | Cod sursa (job #2098363) | Cod sursa (job #2294382) | Cod sursa (job #2194716)
#include<fstream>
using namespace std;
ifstream in ("inversmodular.in");
ofstream out ("inversmodular.out");
int a,b;
void cmmdc (int &x, int &y, int a, int b) {
if (b == 0) {
x = 1;
y = 0;
}
else {
int ax,ay;
cmmdc (ax,ay,b,a%b);
x = ay;
y = ax - (a/b)*ay;
}
}
int main (void) {
in >> a >> b;
int x,y;
cmmdc (x,y,a,b);
if (x <= 0) {
x = b + x % b;
}
out << x;
return 0;
}