Pagini recente » Cod sursa (job #2437555) | Cod sursa (job #2934302) | Cod sursa (job #2436468) | Cod sursa (job #213520) | Cod sursa (job #2497098)
#include <fstream>
#include <vector>
using namespace std;
char const in_file[] = "inversmodular.in";
char const out_file[] = "inversmodular.out";
ifstream Read(in_file);
ofstream Write(out_file);
void GCD(
uint32_t const first,
uint32_t const second,
uint32_t &x,
uint32_t &y
) {
if (second == 0) {
x = 1;
y = 0;
return;
}
uint32_t x0;
uint32_t y0;
GCD(second, first % second, x0, y0);
x = y0;
y = x0 - (first / second) * y0;
}
int main() {
uint32_t a;
uint32_t n;
Read >> a;
Read >> n;
uint32_t x;
uint32_t y;
GCD(a, n, x, y);
while (x < 0) {
x += n;
}
Write << x;
Read.close();
Write.close();
return 0;
}