Pagini recente » Cod sursa (job #1251623) | Cod sursa (job #1383827) | Cod sursa (job #401557) | Cod sursa (job #529157) | Cod sursa (job #2183954)
#include <iostream>
#include <fstream>
using namespace std;
void euclid(int a, int b, int &x, int &y)
{
if (b==0)
{
x=1;
y=0;
return;
}
euclid(b, a%b, x, y);
int aux=y;
y=x-(a/b)*y;
x=aux;
}
int main()
{
ifstream fin("inversmodular.in");
ofstream fout("inversmodular.out");
int a, b, x, y;
fin >> a >> b;
euclid(a, b, x, y);
while(x<0)
x+=b;
fout << x;
return 0;
}