Pagini recente » Cod sursa (job #2272249) | Cod sursa (job #2671302) | Cod sursa (job #2973145) | Cod sursa (job #2169718) | Cod sursa (job #2649124)
#include <iostream>
#include <fstream>
using namespace std;
typedef long long ll;
ifstream in("inversmodular.in");
ofstream out("inversmodular.out");
ll a, b, d, yy, xx;
ll gcd(ll a, ll b, ll &x, ll &y)
{
if(!b)
{
x=1, y=0;
return a;
}
ll rez, y1, x1;
rez=gcd(b, a%b, x1, y1);
x=y1;
y=x1-(a/b)*y1;
return rez;
}
int main()
{
in>>a>>b;
d=gcd(a, b, xx, yy);
if(xx<=0) xx=b+a%b;
out<<xx;
return 0;
}