/* ax+by=1, get the value of x of min positive value */ int getUniqueReciprocal(int a, int m) { //if (a == 0 || m == 0) // return -1; //int x = a > m ? a : m; //int y = a >=m ? m : a; //int r,q; //vector<int> mV; //mV.push_back(x); //mV.push_back(y); //string exp; //while (y) //{ // q = x / y; // r = x%y; // exp = intParseStr(x) + "=" + intParseStr(y) +"*"+intParseStr(q) + "+" + intParseStr(r) + ";"; // cout << exp; // x = y; // y = r; // mV.push_back(y); //} //mV.pop_back(); //remove the last element 1 //cout << "\n" << "reverse progress" <<"\n"<<"1="; //int newA, newB, newX, newY; //int top = 1; //while (mV.size() > 1) //{ // int rLast = mV.back(),rSecond=mV.at(mV.size()-2); //} if (getGcd(a, m) != 1) { cout << "no unique reciprocal" << endl; exit(0); } int x = 0; for (x = 1; x < m; x++) { if ((a*x - 1) % m == 0) return x; } return 0; }
int getLcm(int a, int b) { int mcd = getGcd(a, b); return a*b / mcd; }
/** * \return Simlified fraction for the given fraction (numerator/denomiator). */ void RMath::simplify(int numerator, int denominator, int& numeratorRes, int& denominatorRes) { int g = getGcd(numerator, denominator); numeratorRes = numerator/g; denominatorRes = denominator/g; }