Pagini recente » Cod sursa (job #3142562) | Cod sursa (job #2284410) | Cod sursa (job #3185837) | Cod sursa (job #3121564)
#include <fstream>
using namespace std;
ifstream fin("inversmodular.in");
ofstream fout("inversmodular.out");
void extended_euclid(int a, int b, int &x, int &y) {
if(!b){
x = 1;
y = 0;
}else{
int x0, y0;
extended_euclid(b, a % b, x0, y0);
x = y0;
y = x0 - (a / b) * y0;
}
}
int main() {
int a, n, x, y;
fin >> a >> n;
extended_euclid(a, n, x, y);
fout << x << '\n';
fin.close();
fout.close();
return 0;
}