Pagini recente » Cod sursa (job #2921177) | Cod sursa (job #1906481) | Cod sursa (job #2937020) | Cod sursa (job #1332602) | Cod sursa (job #1378404)
#include <fstream>
using namespace std;
ifstream is("inversmodular.in");
ofstream os("inversmodular.out");
int n, a, b;
void Euclid( int a, int b, int& x, int &y );
int main()
{
is >> a >> b;
int x, y;
Euclid( a, b, x, y );
if ( x <= 0 )
x += b;
os << x;
is.close();
os.close();
return 0;
}
void Euclid( int a, int b, int& x, int &y )
{
if ( b == 0 )
{
x = 1;
y = 0;
return;
}
int x0, y0;
Euclid( b, a % b, x0, y0 );
x = y0;
y = x0 - ( a / b ) * y0;
}