Cod sursa(job #2751139)
| Utilizator | Data | 14 mai 2021 12:52:50 | |
|---|---|---|---|
| Problema | Invers modular | Scor | 50 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva educationala | Marime | 0.46 kb |
#include <bits/stdc++.h>
using namespace std;
ifstream fin("inversmodular.in");
ofstream fout("inversmodular.out");
int gcd(int a, int b, int &x, int &y) {
if(b == 0) {
x = 1;
y = 0;
return a;
}
int x0, y0;
int d = gcd(b, a % b, x0, y0);
x = y0;
y = x0 - y0 * (a / b);
return d;
}
int main() {
int A, N;
fin >> A >> N;
int x, y;
int d = gcd(A, N, x, y);
// if(d != 1) {
// cout << "test gresit!";
// return 0;
// }
fout << x << '\n';
return 0;
}