Pagini recente » Monitorul de evaluare | Cod sursa (job #1174833) | Cod sursa (job #2781666) | Cod sursa (job #587058) | Cod sursa (job #1040992)
#include <iostream>
#include <fstream>
using namespace std;
ifstream fin("inversmodular.in");
ofstream fout("inversmodular.out");
int c, n;
void Euclid(int a, int b, int &x, int &y)
{
if(!b)
{
x = 1;
y = 0;
}
else
{
int x0, y0;
Euclid(b, a%b, x0, y0);
x = y0;
y = x0 - (a / b) * y0;
}
}
int main()
{
int x = 0, y;
fin>>c>>n;
Euclid(c, n, x, y);
if(x <= 0)
x = n + x % n;
fout<<x;
return 0;
}