Pagini recente » Cod sursa (job #1710938) | Cod sursa (job #2077668) | Cod sursa (job #2803391) | Cod sursa (job #688636) | Cod sursa (job #1060892)
#include<fstream>
using namespace std;
ifstream fin("inversmodular.in");
ofstream fout("inversmodular.out");
void euclid_ext(int a, int b, int &x, int &y)
{
if (b == 0)
{
x = 1;
y = 0;
}
else
{
int x0, y0;
euclid_ext(b, a%b, x0, y0);
x = y0;
y = x0 - (a / b)*y0;
}
}
int main()
{
int A, N, x, y;
fin >> A >> N;
euclid_ext(A, N, x, y);
if (x < 0)
x = (x + N)%N;
fout<<x<<'\n';
return 0;
}