Cod sursa(job #822839)
| Utilizator | Data | 24 noiembrie 2012 07:45:35 | |
|---|---|---|---|
| Problema | Invers modular | Scor | 50 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.5 kb |
#include <iostream>
#include <fstream>
using namespace std;
void euclid_extins(long long a, long long b, long long *d, long long *x, long long *y)
{
if (b == 0)
{
*d = a;
*x = 1;
*y = 0;
}
else
{
long long x0, y0;
euclid_extins(b, a % b, d, &x0, &y0);
*x = y0;
*y = x0 - (a / b) * y0;
}
}
int main ()
{
long long A,N,d,x,y;
ifstream fi("inversmodular.in");
ofstream fo("inversmodular.out");
fi>>A>>N;
euclid_extins(A,N,&d,&x,&y);
fo << x << "\n";
return 0;
}