Pagini recente » Cod sursa (job #305122) | Istoria paginii runda/party/clasament | Cod sursa (job #779611) | Istoria paginii runda/bulianii_007/clasament | Cod sursa (job #2741482)
#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;
}