Cod sursa(job #1689641)
Utilizator | Data | 14 aprilie 2016 14:02:20 | |
---|---|---|---|
Problema | Invers modular | Scor | 100 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.52 kb |
#include <fstream>
using namespace std;
ifstream f("inversmodular.in");
ofstream g("inversmodular.out");
int a, b, x, y;
int euclid(int a, int b, int &x, int &y)
{
if (b == 0)
{
x = 1;
y = 0;
return a;
}
else
{
int xx, yy;
euclid(b, a % b, xx, yy);
x = yy;
y = xx - (a / b) * yy;
}
}
int main()
{
f >> a >> b;
euclid(a, b, x, y);
while (x < 0)
x += b;
g << x << '\n';
return 0;
}