Pagini recente » Cod sursa (job #2473401) | Cod sursa (job #1886214) | Cod sursa (job #2582482) | Cod sursa (job #2503794) | Cod sursa (job #2909137)
#include <iostream>
#include <fstream>
using namespace std;
ifstream fin("inversmodular.in");
ofstream fout("inversmodular.out");
int x, y, d;
void cmmdc(int a, int b, int &d, int &x, int &y)
{
if(b == 0)
{
x = 1; y = 0; d = a;
}
else
{
int x0, y0;
cmmdc(b, a % b, d, x0, y0);
x = y0;
y = x0 - (a / b) * y0;
}
}
int main()
{
int a = 5, m = 7;
fin >> a >> m;
cmmdc(a, m, d, x, y);
while(x <= 0)
x = x + m;
fout << x;
return 0;
}