Cod sursa(job #1921150)
| Utilizator | Data | 10 martie 2017 11:33:46 | |
|---|---|---|---|
| Problema | Invers modular | Scor | 100 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.51 kb |
#include <fstream>
using namespace std;
ifstream fin("inversmodular.in");
ofstream fout("inversmodular.out");
int A, N;
long long euclidExt(int a, int b, long long &x, long long &y)
{
if(b==0)
{
x=1;
y=0;
return a;
}
long long x0, y0, d;
d=euclidExt(b, a%b, x0, y0);
x=y0;
y=x0-(a/b)*y0;
return d;
}
int main()
{
fin>>A>>N;
long long X, Y, D;
D=euclidExt(A, N, X, Y);
if(X<=0)
X=N+X%N;
fout<<X;
}
