Pagini recente » Cod sursa (job #2318432) | Cod sursa (job #548748) | Cod sursa (job #424588) | Cod sursa (job #2509640) | Cod sursa (job #2499643)
#include <fstream>
#include <bitset>
using namespace std;
ifstream fin("invermodular.in");
ofstream fout("inversmodular.out");
long long a, b, c, d, x, y,t;
long long euclid(long long a, long long b, long long &x, long long &y)
{
if(b==0)
{
x=1,y=0;
return a;
}
long long d,xa,ya;
d=euclid(b, a%b, xa, ya);
x=ya,y=xa-a/b*ya;
return d;
}
int main()
{
fin>>a>>b;
d=euclid(a, b, x, y);
if(x<=0) x+=b;
fout<<x;
return 0;
}