Assuming that the cost of the operation is pow O(P(n)) for some function P , the global cost of the cycle is O(√nP(n)) . If the pow call is taken out of the loop and executed only once, the cost is expressed as O(√n+P(n)) .
In the case of P(n)=1 this gives O(√n) and O(√n) respectively.
In the case of P(n)=log(n) this gives O(√n.log(n)) and O(√n) .
[the youngest member of the amount is absorbed by another.]
The assumption P(n)=log(n) may be valid in the context of arbitrary precision integers, where at least O(log(n)) bits are required to represent the integer n . But this only makes sense for huge n values.
source share