n(n+1)/2 belongs to O(n^3)
What is the time complexity of the following algorithm power(n,x)? Assume that each operation takes a unit time.
LongPower(int n, int x) {
long ans;
if(n == 0)
return 1;
else {
ans = Power(n/2, x) * Power(n/2, x);
if(n % 2 == 1)
ans *= x;
return ans;
}
}
A: (n)
B: (logn)
C: (n logn)
D: (n^2)
E: None of the above