Cod sursa(job #1950917)
Utilizator | Andrei Maria andrei232000 | Data | 3 aprilie 2017 12:40:21 |
---|---|---|---|
Problema | Invers modular | Scor | 100 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.55 kb |
#include <fstream>
using namespace std;
ifstream fin("inversmodular.in");
ofstream fout("inversmodular.out");
long long A, N, X, Y;
void euclid(long long a, long long b, long long &x, long long &y)
{
if(b)
{
euclid(b, a % b, x, y);
long long x0, y0;
x0 = x;
y0 = y;
x = y0;
y = x0 - y0 * (a / b);
}
else
{
x = 1;
y = 0;
}
}
int main()
{
fin>>A>>N;
euclid(A, N, X, Y);
while(X < 0)
{
X += N;
}
fout<<X<<'\n';
}