Pagini recente » Cod sursa (job #1938625) | Cod sursa (job #592466) | Cod sursa (job #161580) | Cod sursa (job #2274451) | Cod sursa (job #2197935)
#include <iostream>
#include <fstream>
using namespace std;
ifstream f("inversmodular.in");
ofstream g("inversmodular.out");
void Euclid_extins_iterativa(int a, int b, int &d, int &x, int &y)
{
int x1 = 0, y1 = 1;
x = 1, y = 0;
while(b != 0)
{
int q = a / b;
int r = a % b;
a = b;
b = r;
int x0 = x - x1 * q;
int y0 = y - y1 * q;
x = x1;
y = y1;
x1 = x0;
y1 = y0;
}
d = a;
}
int main()
{
int A, N, x, y, d;
f >> A >> N;
Euclid_extins_iterativa(A, N, d, x, y);
if(x < 0) x += N;
g << x;
return 0;
}