Cod sursa(job #1608487)
| Utilizator | Data | 22 februarie 2016 09:38:24 | |
|---|---|---|---|
| Problema | Invers modular | Scor | 100 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.57 kb |
#include <fstream>
using namespace std;
ifstream is("inversmodular.in");
ofstream os("inversmodular.out");
int a, n;
void EuclidE(long long & x, long long &y, int a, int n)
{
if(n == 0)
{
x = 1;
y = 0;
}
else
{
EuclidE(x, y, n, a%n);
long long aux = x;
x = y;
y = aux - y * (a/n);
}
}
int main()
{
is >> a >> n;
long long x = 0, y = 0;
EuclidE(x, y, a, n);
if(x <= 0)
x = n + x%n;
os << x;
is.close();
os.close();
return 0;
}
