Cod sursa(job #2883470)
| Utilizator | Data | 1 aprilie 2022 15:40:20 | |
|---|---|---|---|
| Problema | Invers modular | Scor | 100 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva educationala | Marime | 0.53 kb |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
void gcd(ll &x, ll &y, int a, int b) {
if (!b)
x = 1, y = 0;
else {
gcd(x, y, b, a % b);
ll aux = x;
x = y;
y = aux - y * (a / b);
}
}
int main() {
ifstream in("inversmodular.in");
ofstream out("inversmodular.out");
ll a, n, inv = 0, ins;
in >> a >> n;
gcd(inv, ins, a, n);
if (inv <= 0)
inv = n + inv % n;
out << inv;
return 0;
}
