Cod sursa(job #1221132)
| Utilizator | Data | 19 august 2014 16:54:50 | |
|---|---|---|---|
| Problema | Invers modular | Scor | 100 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.47 kb |
#include <fstream>
using namespace std;
ifstream fin("inversmodular.in");
ofstream fout("inversmodular.out");
int A, B, X, Y;
void Solve(int A, int B, int &X, int &Y)
{
if (!B)
X = 1, Y = 0;
else
{
Solve(B, A % B, X, Y);
int aux = X;
X = Y;
Y = aux - A / B * Y;
}
}
int main()
{
fin >> A >> B;
Solve(A, B, X, Y);
while (X <= 0)
{
X += B;
}
fout << X << '\n';
fout.close();
return 0;
}
