Cod sursa(job #2257947)
Utilizator | Data | 10 octombrie 2018 17:47:21 | |
---|---|---|---|
Problema | Invers modular | Scor | 100 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.56 kb |
#include <fstream>
using namespace std;
#define ll long long
ifstream in("inversmodular.in");
ofstream out("inversmodular.out");
ll a,b,x1,y1;
void Euclid_Extins(ll a , ll b , ll &x , ll &y){
if(!b) x = 1, y = 0;
else {
Euclid_Extins(b,a%b,x,y);
ll aux = x;
x = y;
y = aux - y * (a/b);
}
}
int main(){
in >> a >> b;
Euclid_Extins(a,b,x1,y1);
if(x1 <= 0){
x1 = b + x1%b;
}
out << x1;
in.close();
out.close();
return 0;
}