Pagini recente » Rotatie lexicografic minima | Cod sursa (job #2043269) | Cod sursa (job #609271) | Cod sursa (job #3243094) | Cod sursa (job #1950917)
#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';
}