Important note: power does not assume that multiplication is
commutative, but it does rely crucially on the fact that
multiplication is associative. If you have defined * or
MonoidOperation to be a non-associative operation, then powerwill give you the wrong answer. [2]

Definition

Defined in the standard header numeric, and in the nonstandard
backward-compatibility header algo.h. This function is an SGI
extension; it is not part of the C++ standard.

Preconditions

n >= 0.

Complexity

The number of multiplications (or, in the case of the second version,
the number of applications of MonoidOperation) is lg(n) + nu(n)
where lg is the base 2 logarithm and nu(n) is the number of
1s in the binary representation of n. [3]

Example

int main() {
cout << "2 ** 30 = " << power(2, 30) << endl;
}

Notes

[1]
This is a conceptual description of what power's return value
is; it is not how power is actually implemented. If power
were implemented that way then it would require n-1 multiplications,
which would be grossly inefficient. Power is implemented using
the "Russian peasant algorithm", which requires only O(log n)
multiplications.
See section 4.6.3 of Knuth (D. E. Knuth, The Art of Computer
Programming. Volume 2: Seminumerical Algorithms,
Addison-Wesley, 1981) for a discussion.