Pagini recente » Cod sursa (job #2936547) | Cod sursa (job #2457022) | Cod sursa (job #2251801) | Cod sursa (job #2391713) | Cod sursa (job #2873680)
#include <iostream>
#include <fstream>
using namespace std;
ifstream fin("inversmodular.in");
ofstream fout("inversmodular.out");
#define MOD 1999999973
void euclid(int a, int b, int &d, int &x, int &y)
{
if(b == 0)
{
x = 1;
y = 0;
d = a;
return;
}
int x1, y1;
euclid(b, a%b, d, x1, y1);
x = y1;
y = x1 - (a/b)*y1;
}
int main()
{
int d,x,y;
long long a,b;
fin>>a>>b;
euclid(a,b,d,x,y);
while(x<0)
x=x+b;
fout<<x;
return 0;
}