Pagini recente » Cod sursa (job #1707364) | Cod sursa (job #2880473) | Cod sursa (job #2549689) | Cod sursa (job #2696020) | Cod sursa (job #991193)
Cod sursa(job #991193)
#include <fstream>
#include <cmath>
using namespace std;
void gcd(int a, int b, int &x, int &y)
{
if(b == 0)
{
x = 1;
y = 0;
return ;
}
int x0, y0;
gcd(b, a % b, x0, y0);
x = y0;
y = x0 - (a / b) * y0;
}
int main()
{
ifstream fin("inversmodular.in");
ofstream fout("inversmodular.out");
int a, x, n, y;
fin >> a >> n;
gcd(a, n, x, y);
fout << x << " " << y << '\n';
int mul = abs(x / n);
if(x < 0)
{
x += (mul + 1) * n;
}
fout << x << '\n';
return 0;
}