Cod sursa(job #2257919)
Utilizator | Ciocirlan Robert ciocirlanr | Data | 10 octombrie 2018 17:23:34 |
---|---|---|---|
Problema | Invers modular | Scor | 0 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.56 kb |
#include <fstream>
using namespace std;
#define ll long long
ifstream in("invermodular.in");
ofstream out("invermodular.out");
long long a,b,x,y;
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);
int aux = x;
x = y;
y = aux - y * (a/b);
}
}
int main(){
in >> a >> b;
Euclid_Extins(a,b,x,y);
out << x;
while(x < 0)
x = b + x%b;
in.close();
out.close();
return 0;
}