Pagini recente » Cod sursa (job #381430) | Cod sursa (job #1117746) | Cod sursa (job #2344175) | Cod sursa (job #3131465) | Cod sursa (job #2171438)
#include <fstream>
using namespace std;
ifstream fin("inversmodular.in");
ofstream fout("inversmodular.out");
int A, N;
long long w, k;
void rid(long long &x, long long &y, int a, int b)
{
if (!b)
{
x=1;
y=0;
}
else
{
rid(x, y, b, a%b);
int aux=x;
x=y;
y=aux-y*(a/b);
}
}
int main()
{
fin>>A>>N;
w=0; k=0;
rid(w, k, A, N);
if (w<=0)
{
w=N+w%N;
}
fout<<w;
return 0;
}