Pagini recente » Cod sursa (job #579911) | Cod sursa (job #1197971) | Cod sursa (job #187199) | Cod sursa (job #2911622) | Cod sursa (job #1491592)
#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;
}