Cod sursa(job #2331254)
Utilizator | Data | 29 ianuarie 2019 13:32:48 | |
---|---|---|---|
Problema | Invers modular | Scor | 100 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva educationala | Marime | 0.45 kb |
#include <fstream>
using namespace std;
ifstream fin("inversmodular.in");
ofstream fout("inversmodular.out");
int a, x, m, y;
void euclid(int a, int b, int &x, int &y){
if(b == 0){
x = 1;
y = 0;
return;
}
int x0, y0;
euclid(b, a%b, x0, y0);
x = y0;
y = x0 - y0*(a/b);
}
int main(){
fin>>a>>m;
euclid(a, m, x, y);
if(x < 0)
x += m;
fout<<x;
return 0;
}