Cod sursa(job #2884196)
Utilizator | Cristian Alexutan DooMeD | Data | 2 aprilie 2022 16:04:21 |
---|---|---|---|
Problema | Invers modular | Scor | 100 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva educationala | Marime | 0.43 kb |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
void euclid(ll a, ll b, ll &d, ll &x, ll &y) {
if(b==0) {
d = a;
x = 1;
y = 0;
}
else {
ll x1, y1;
euclid(b, a%b, d, x1, y1);
x = y1;
y = x1 - 1LL * (a / b) * y1;
}
}
int main() {
ifstream f("inversmodular.in");
ofstream g("inversmodular.out");
ll a, n; f >> a >> n;
ll d, x, y;
euclid(a, n, d, x, y);
while(x<0) x+=n;
g << x;
return 0;
}