The O(log n) calculation is performed n times.