Cod sursa(job #1491592)
Utilizator | cont-vechi azkaban | Data | 25 septembrie 2015 18:38:42 |
---|---|---|---|
Problema | Invers modular | Scor | 100 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.47 kb |
#include <fstream>
using namespace std;
ifstream cin("inversmodular.in");
ofstream cout("inversmodular.out");
long long t,a,b,x,y,c;
int _gcd_Extended(int a,int b){
if (b==0) {
x = 1;
y = 0;
return a;
}
int next = _gcd_Extended(b,a%b);
long long aux = x;
x = y;
y = aux - (a/b)*y;
return next;
}
int main(void) {
cin>>a>>b;
_gcd_Extended(a,b);
if (x<0) cout<<x+b;
else cout<<x;
return 0;
}