Cod sursa(job #3290658)
Utilizator | Data | 31 martie 2025 15:10:44 | |
---|---|---|---|
Problema | Invers modular | Scor | 100 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva educationala | Marime | 0.5 kb |
#include<bits/stdc++.h>
#define int long long
using namespace std;
void euclid(int a, int b, int & x, int & y)
{
if(b == 0)
{
x = 1, y = 0;
}
else
{
euclid(b, a % b , x, y);
int aux = x;
x = y;
y = aux - (a / b) * y;
}
}
int32_t main()
{
freopen("inversmodular.in", "r", stdin);
freopen("inversmodular.out", "w", stdout);
int a, b, c, x, y, ans;
cin >> a >> b;
euclid(a, b, x, y);
cout << (x + b) % b;
}