Cod sursa(job #2039050)
Utilizator | Data | 14 octombrie 2017 10:50:04 | |
---|---|---|---|
Problema | Invers modular | Scor | 50 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.33 kb |
#include <fstream>
#define ll long long
std::ifstream in("inversmodular.in");
std::ofstream out("inversmodular.out");
std::pair<ll, ll> ext(int a, int b) {
if (!b) return { 1, 0 };
auto p = ext(b, a % b);
return { p.second, p.first - (a / b) * p.second };
}
int main() {
int a, n;
in >> a >> n;
out << ext(a, n).first;
return 0;
}