Pagini recente » Cod sursa (job #2693492) | Cod sursa (job #2189890) | Cod sursa (job #2828945) | Cod sursa (job #107536) | Cod sursa (job #1275376)
#include <fstream>
using namespace std;
void cmmdc (int a, int b, int& x, int& y)
{
if (b == 0)
{
x = 1;
y = 0;
return;
}
int x0, y0;
cmmdc(b, a%b, x0, y0);
x = y0;
y = x0 - (a/b) * y0;
}
int main()
{
ifstream in("inversmodular.in");
ofstream out("inversmodular.out");
int a, b, x, y;
in>>a>>b;
cmmdc(a, b, x, y);
while(x<0)
x+=b;
out<<x;
in.close();
out.close();
return 0;
}