Pagini recente » Cod sursa (job #2935509) | Diferente pentru problema/aib intre reviziile 5 si 4 | Cod sursa (job #1626037) | Monitorul de evaluare | Cod sursa (job #2230638)
#include <fstream>
using namespace std;
ifstream in("inversmodular.in");
ofstream out("inversmodular.out");
void euclid(int &x,int &y,int a,int b){
if(!b)
{
x=1;
y=0;
return ;
}
euclid(x,y,b,a%b);
int newx=y;
int newy=x-y*(a/b);
x=newx;
y=newy;
}
int main()
{
int x,y,a,b;
in>>a>>b;
euclid(x,y,a,b);
x %=b;
if(x<0)
x+=b;
out<<x;
return 0;
}