Cod sursa(job #610260)
Utilizator | Data | 26 august 2011 08:44:48 | |
---|---|---|---|
Problema | Invers modular | Scor | 100 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.49 kb |
#include <fstream.h>
long euclid (long a, long b, long &x, long &y)
{
if (b == 0)
{
x = 1;
y = 0;
return a;
}
long x0, y0, d;
d = euclid (b, a % b, x0, y0);
x = y0;
y = x0 - (a / b) * y0;
return d;
}
int main ()
{
long a, b, x, y, d;
ifstream fin ("inversmodular.in");
ofstream fout ("inversmodular.out");
fin >> a >> b;
d = euclid (a, b, x, y);
x *= (1 / d);
while (x <= 0)
{
x += b;
}
fout << x;
fin.close ();
fout.close ();
return 0;
}