Pagini recente » Cod sursa (job #2481396) | Cod sursa (job #2975585) | Cod sursa (job #1168905) | Cod sursa (job #2245917) | Cod sursa (job #610259)
Cod sursa(job #610259)
#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, c, 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;
}
fin.close ();
fout.close ();
return 0;
}