Cod sursa(job #2257713)
| Utilizator | Data | 10 octombrie 2018 13:51:07 | |
|---|---|---|---|
| Problema | Invers modular | Scor | 100 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.54 kb |
#include <fstream>
using namespace std;
using ll = long long;
ifstream fin("inversmodular.in");
ofstream fout("inversmodular.out");
void gcd(ll &x, ll &y, ll a, ll b)
{
if (!b)
{
x = 1;
y = 0;
}
else
{
gcd(x, y, b, a % b);
ll aux = x;
x = y;
y = aux - y * (a / b);
}
}
int main()
{
int a, n;
ll inv = 0, ins;
fin >> a >> n;
gcd(inv, ins, a, n);
if (inv <= 0)
inv = n + inv % n;
fout << inv << '\n';
return 0;
}
