Cod sursa(job #2370054)
Utilizator | Data | 6 martie 2019 10:30:55 | |
---|---|---|---|
Problema | Invers modular | Scor | 50 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva educationala | Marime | 0.46 kb |
#include <fstream>
using namespace std;
ifstream inf("inversmodular.in");
ofstream outf("inversmodular.out");
int modinv(int a, int b) {
long long x1 = 1, x2 = 0, q, aux;
while(b) {
q = a / b;
aux = b;
b = a - q * b;
a = aux;
aux = x2;
x2 = x1 - q * x2;
x1 = aux;
}
return x1;
}
int main() {
int a, b;
inf >> a >> b;
outf << modinv(a, b);
return 0;
}