Cod sursa(job #720789)
Utilizator | Data | 22 martie 2012 21:49:03 | |
---|---|---|---|
Problema | Invers modular | Scor | 0 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.48 kb |
#include <fstream>
using namespace std;
inline void euclid(int a, int b, long long &x, long long &y)
{
if (b == 0)
{
x = 1;
y = 0;
}
else
{
int x0, y0;
euclid (b, a%b, x0, y0);
x = y0;
y = x0 - (a/b)*y0;
}
}
int main()
{
int a, n;
long long x, y;
ifstream f("inversmodular.in");
f>>a>>n;
f.close();
euclid(a, n, x, y);
if (x<=0)
x += n;
ofstream g("inversmodular.out");
g<<x<<"\n";
g.close();
return 0;
}