Cod sursa(job #2194716)
| Utilizator | Data | 14 aprilie 2018 10:42:37 | |
|---|---|---|---|
| Problema | Invers modular | Scor | 100 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.49 kb |
#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;
}
