Cod sursa(job #1300968)
Utilizator | Data | 25 decembrie 2014 12:44:39 | |
---|---|---|---|
Problema | Invers modular | Scor | 100 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.54 kb |
#include <fstream>
using namespace std;
ifstream is("inversmodular.in");
ofstream os("inversmodular.out");
void EDC(int a, int b, int &x, int &y);
int a, b;
int x, y;
int main()
{
is >> a >> b;
EDC( a, b, x, y );
if ( x <= 0 )
x += b;
os << x;
is.close();
os.close();
return 0;
}
void EDC(int a, int b, int &x, int &y)
{
if(b == 0)
{
x = 1;
y = 0;
return;
}
int x0, y0;
EDC(b, a % b, x0, y0);
x = y0;
y = x0 - (a / b) * y0;
}