Cod sursa(job #2555391)
| Utilizator | Data | 23 februarie 2020 22:52:15 | |
|---|---|---|---|
| Problema | Invers modular | Scor | 0 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva educationala | Marime | 0.54 kb |
#include <iostream>
#include <fstream>
using namespace std;
ifstream r("inversmodular.in");
ofstream w("inversmodular.out");
int A, N;
void Euclid(long long cx, long long cy, int a, int b)
{
if (!b)
{
cx=1;
cy=0;
}
else
{
Euclid(cx, cy, b, a%b);
long long aux=cx;
cx=cy;
cy=aux-cy*(a/b);
}
}
int main()
{
long long inv=0, ins;
r>>A>>N;
Euclid(inv, ins, A, N);
if (inv <= 0)
{
inv=N+inv%N;
}
w<<inv;
return 0;
}
