Pagini recente » Cod sursa (job #783650) | Cod sursa (job #1639672) | Cod sursa (job #2823828) | Cod sursa (job #2146804) | Cod sursa (job #3165845)
#include <bits/stdc++.h>
using namespace std;
ifstream fin("inversmodular.in");
ofstream fout("inversmodular.out");
int A, N;
void Euclid(int a, int b, int &x, int &y)
{
if (!b) { x = 1; y = 0; }
else
{
int x0, y0;
Euclid(b, a % b, x0, y0);
x = y0;
y = x0 - (a / b) * y0;
}
}
void Rezolvare()
{
fin >> A >> N;
int x, y;
Euclid(A, N, x, y);
while (x < 0)
x += N;
fout << x << '\n';
}
int main()
{
Rezolvare();
fin.close();
fout.close();
return 0;
}