Pagini recente » Cod sursa (job #1857175) | Cod sursa (job #1435340) | Cod sursa (job #2134493) | Cod sursa (job #781295) | Cod sursa (job #2270548)
#include <iostream>
#include <fstream>
using namespace std;
void euclid(int a, int b, int &d, int &x, int &y)
{
if (b == 0)
{
if (d%a!=0)
x=0;
else
x = d/a;
y = 0;
}
else
{
int x0, y0;
euclid(b, a % b, d, x0, y0);
x = y0;
y = x0 - (a / b) * y0;
}
}
int main()
{
ifstream fin ("inversmodular.in");
ofstream fout ("inversmodular.out");
int a,n,c,x,y;
fin>>a>>n;
c=1;
euclid(a, n, c, x, y);
fout<<x<<'\n';
return 0;
}