Cod sursa(job #2476773)
| Utilizator | Data | 19 octombrie 2019 11:26:02 | |
|---|---|---|---|
| Problema | Invers modular | Scor | 50 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva educationala | Marime | 0.48 kb |
#include <iostream>
#include <fstream>
#define ll long long
using namespace std;
ifstream fin("inversmodular.in");
ofstream fout("inversmodular.out");
void gcdExtended(ll a, ll b, ll &x, ll &y) {
if (!b) {
x = 1;
y = 0;
return;
}
gcdExtended(b, a % b, x, y);
ll aux = x;
x = y;
y = aux - (a / b) * y;
}
int main() {
ll a, n, x, y;
fin >> a >> n;
gcdExtended(a, n, x, y);
fout << x;
return 0;
}
