Cod sursa(job #2900861)
Utilizator | Poinaru-Rares-Aurel RaresPoinaru | Data | 12 mai 2022 11:39:04 |
---|---|---|---|
Problema | Invers modular | Scor | 100 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva educationala | Marime | 0.52 kb |
#include <fstream>
std::ifstream fin("inversmodular.in");
std::ofstream fout("inversmodular.out");
inline void euclid(long long int a, long long int b, long long int &x, long long int &y) {
if (b == 0)
x = y = 1;
else {
long long int x1, y1;
euclid(b, a % b, x1, y1);
x = y1;
y = x1 - a / b * y1;
}
}
int main() {
long long int a, MOD, x, y;
fin >> a >> MOD;
euclid(a, MOD, x, y);
while (x < 0)
x += MOD;
fout << x;
return 0;
}