Cod sursa(job #2873665)
Utilizator | Data | 19 martie 2022 11:17:05 | |
---|---|---|---|
Problema | Invers modular | Scor | 0 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva educationala | Marime | 0.52 kb |
#include <fstream>
typedef long long ll;
using namespace std;
ifstream cin("inversmodular.in");
ofstream cout("inversmodular.in");
void euclid(ll a, ll b, ll &x, ll &y)
{
if (b == 0)
{
x = 1, y = 0;
return;
}
else
{
ll x1, y1;
euclid(b, a % b, x1, y1);
x = y1;
y = x1 - a / b * y1;
}
}
int main()
{
ll a,b,x,y;
cin >> a>>b;
euclid(a, b, x, y);
if (x <= 0)
x = b + x % b;
cout << x;
return 0;
}