Cod sursa(job #791948)
| Utilizator | Data | 25 septembrie 2012 20:13:37 | |
|---|---|---|---|
| Problema | Invers modular | Scor | 50 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.61 kb |
#include <fstream>
using namespace std;
void euclidext(long long int a, long long int b, long long int &x, long long int &y, long long int &d)
{
if(!b)
{
x = 1, y = 0, d = a;
}
else
{
long long int x0, y0;
euclidext(b,a%b,x0,y0,d);
x = y0;
y = x0 - (a/b)*y0;
}
}
int main()
{
long long int a,x,y,d,n;
d = 1;
ifstream f("inversmodular.in");
f >> a >> n;
f.close();
euclidext(a,n,x,y,d);
if(a <= 0)
x = n + x % n;
ofstream g("inversmodular.out");
g << x;
g.close();
return 0;
}
