Pagini recente » Cod sursa (job #2065205) | Cod sursa (job #3313329) | Cod sursa (job #3347140) | Cod sursa (job #1000170) | Cod sursa (job #3336998)
#include <bits/stdc++.h>
using namespace std;
#define USE_STD_IO 0
#if USE_STD_IO
#define fin cin
#define fout cout
#else
ifstream fin("inversmodular.in");
ofstream fout("inversmodular.out");
#endif
int a, n, x, y;
static inline void EuclidExt(int a, int b, int& x, int& y) {
if(0 == b) {
x = 1;
y = 0;
}
else {
int x1, y1;
EuclidExt(b, a % b, x1, y1);
x = y1;
y = x1 - (a / b) * y1;
}
}
int main() {
if(USE_STD_IO) ios_base::sync_with_stdio(false);
fin.tie(NULL);
fout.tie(NULL);
fin >> a >> n;
EuclidExt(a, n, x, y);
while(x < 0) x += n;
fout << x;
return 0;
}