Cod sursa(job #2878574)
| Utilizator | Data | 27 martie 2022 12:21:35 | |
|---|---|---|---|
| Problema | Invers modular | Scor | 100 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva educationala | Marime | 0.53 kb |
#include <fstream>
using namespace std;
ifstream cin("inversmodular.in");
ofstream cout("inversmodular.out");
void euclidth(long long &x, long long &y, int n, int mod)
{
if(!mod){
x = 1;
y = 1;
}
else{
euclidth(x, y, mod, n % mod);
long long aux = x;
x = y;
y = aux - y * (n / mod);
}
}
int main()
{
int a, mod;
cin >> a >> mod;
long long x, y;
euclidth(x, y, a, mod);
while(x < 0)
x += mod;
cout << x;
return 0;
}
