Cod sursa(job #3143920)
| Utilizator | Data | 3 august 2023 11:09:55 | |
|---|---|---|---|
| Problema | Invers modular | Scor | 50 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva educationala | Marime | 0.45 kb |
#include <fstream>
using namespace std;
ifstream cin("inversmodular.in");
ofstream cout("inversmodular.out");
void euclid_extins(int a, int n, int &x, int &y){
if (n == 0){
x = 1;
y = 0;
return;
}
euclid_extins(n, a % n, x, y);
int x2, y2;
x2 = y;
y2 = x - (a / n) * y;
x = x2, y = y2;
}
int main(){
int a, n, x = 1, y = 0;
cin >> a >> n;
euclid_extins(a, n, x, y);
cout << x;
return 0;
}