Pagini recente » Cod sursa (job #2367156) | Cod sursa (job #1612462) | Cod sursa (job #522393) | Cod sursa (job #2971733) | Cod sursa (job #3145041)
#include <fstream>
using namespace std;
ifstream fin("inversmodular.in");
ofstream fout("inversmodular.out");
void euclid(int a, int b, long long &x, long long &y) {
if (b == 0) {
x = 1;
y = 1;
} else {
long long x1, y1;
euclid(b, a % b, x1, y1);
x = y1;
y = x1 - a / b * y1;
}
}
long long invers_modular(int a, int n) {
long long x, y;
euclid(a, n, x, y);
while (x < 0) {
x += n;
}
return x;
}
int main() {
int a, n;
fin >> a >> n;
long long inv_mod = invers_modular(a, n);
fout << inv_mod;
return 0;
}