C - POW Editorial by en_translator

Since \(pow(A,B)\) is quite large, it cannot be computed directly. How can we compare them without actually computing them?

First, we will find the sign of \(pow(A,C)\). It is negative if \(A\) is negative and \(C\) is odd; otherwise it is non-negative.

If the signs of \(pow(A,C)\) and \(pow(B,C)\), then the answer is obvious. Otherwise, the answer can be found as an ordering of \(|A|,|B|\), since \(|pow(A,C)|=pow(|A|,C)\) and \(0\leq x\leq y \Longrightarrow pow(x,z)\leq pow(y,z)\).

Sample code(C++)

last update: