Cod sursa(job #2169597)
| Utilizator | Data | 14 martie 2018 16:16:13 | |
|---|---|---|---|
| Problema | Invers modular | Scor | 50 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.49 kb |
#include <iostream>
#include <fstream>
using namespace std;
ifstream f("inversmodular.in");
ofstream g("inversmodular.out");
int gcd( int A, int B, int &X, int &Y )
{
if (B == 0)
{
X = 1;
Y = 0;
return A;
}
int X0, Y0, D;
D = gcd( B, A % B, X0, Y0 );
X = Y0;
Y = X0 - (A / B) * Y0;
return D;
}
int main()
{
int A,N;
f>>A>>N;
int X,Y;
int D=gcd(A,N,X,Y);
g<<X;
return 0;
}
