Pagini recente » Cod sursa (job #1750917) | Cod sursa (job #1502661) | Cod sursa (job #926134) | Cod sursa (job #915845) | Cod sursa (job #1460951)
#include <fstream>
using namespace std;
ifstream fin("inversmodular.in");
ofstream fout("inversmodular.out");
int A, N;
void EuclidExtins( long long& x, long long& y, int a, int b );
int main()
{
long long x, y;
fin >> A >> N;
EuclidExtins( x, y, A, N );
fout << x << '\n';
fin.close();
fout.close();
return 0;
}
void EuclidExtins( long long& x, long long& y, int a, int b )
{
if ( b == 0 )
x = 1, y = 0;
else
{
EuclidExtins( x, y, b, a % b );
long long aux = x;
x = y;
y = aux - ( a / b ) * y;
}
}