Cod sursa(job #2741482)
Utilizator | Data | 16 aprilie 2021 08:46:24 | |
---|---|---|---|
Problema | Invers modular | Scor | 90 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva educationala | Marime | 0.45 kb |
#include <fstream>
using namespace std;
ifstream fin( "inversmodular.in" );
ofstream fout( "inversmodular.out" );
void euclid_ext( int a, int b, int &x, int &y ) {
int x0, y0;
if ( b == 0 ) {
x = 1, y = 0;
return;
}
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 );
x = (x % n + n) % n;
fout << x;
fin.close();
fout.close();
return 0;
}