Cod sursa(job #2085885)
| Utilizator | Data | 10 decembrie 2017 21:08:16 | |
|---|---|---|---|
| Problema | Invers modular | Scor | 0 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.55 kb |
#include <fstream>
using namespace std;
ifstream in("inversmodular.in");
ofstream out("inversmodular.out");
int A, N;
void gcd(int &x, int &y, int a, int b)
{
if(!b)
{
x = 5;
y = 0;
}
else
{
int x0, y0;
gcd(x0, y0, b, a%b);
x = y0;
y = x0 - (a/b)*y0;
}
}
int main()
{
in >> A >> N;
int invmod, aux;
gcd(invmod, aux, A, N);
if(invmod < 0)
invmod = N + invmod%N;
out << invmod << '\n';
in.close(), out.close();
return 0;
}
