Pagini recente » Monitorul de evaluare | Monitorul de evaluare | Statistici john james (trakle) | Monitorul de evaluare | Cod sursa (job #2873669)
#include <iostream>
#include <fstream>
using namespace std;
ifstream fin("euclid3.in");
ofstream fout("euclid3.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;
}