Cod sursa(job #2703080)
| Utilizator | Data | 7 februarie 2021 08:33:38 | |
|---|---|---|---|
| Problema | Invers modular | Scor | 0 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva educationala | Marime | 0.57 kb |
//#include <iostream>
#include <fstream>
using namespace std;
ifstream cin ("inversmodular.in");
ofstream cout ("inversmodular.out");
int gcd(int a, int b, int& x, int& y) {
if (b == 0) {
x = 1;
y = 0;
return a;
}
int x1, y1;
int d = gcd(b, a % b, x1, y1);
x = y1;
y = x1 - y1 * (a / b);
return d;
}
int main()
{
long long a,n;
cin>>a>>n;
long long x, y;
long long g = gcd(a, n, x, y);
if(g==1)
{
x = (x % n + n) % n;
cout << x;
}
return 0;
}
