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