Cod sursa(job #2171438)
Utilizator | Stan Ioana Ligia IoanaStan | Data | 15 martie 2018 12:22:39 |
---|---|---|---|
Problema | Invers modular | Scor | 100 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.5 kb |
#include <fstream>
using namespace std;
ifstream fin("inversmodular.in");
ofstream fout("inversmodular.out");
int A, N;
long long w, k;
void rid(long long &x, long long &y, int a, int b)
{
if (!b)
{
x=1;
y=0;
}
else
{
rid(x, y, b, a%b);
int aux=x;
x=y;
y=aux-y*(a/b);
}
}
int main()
{
fin>>A>>N;
w=0; k=0;
rid(w, k, A, N);
if (w<=0)
{
w=N+w%N;
}
fout<<w;
return 0;
}