Pagini recente » Clasamentul arhivei de probleme | Cod sursa (job #1412905) | Cod sursa (job #327435) | Cod sursa (job #317492) | Cod sursa (job #2271988)
#include <iostream>
#include <fstream>
using namespace std;
void gcd_extended(int a, int b, int &x, int &y)
{
if (!b)
{
x = 1;
y = 0;
return;
}
gcd_extended(b, a%b, x, y);
int aux = x;
x = y;
y = aux - (a / b) * x;
}
int main()
{
ifstream fin("inversmodular.in");
ofstream fout("inversmodular.out");
int a, n, x, y;
fin >> a >> n;
gcd_extended(a, n, x, y);
if (x < 0)
x += n;
fout << x;
return 0;
}