I need some help with how to calculate Big O for this algorithm.

Say for example you have two functions, X and Y whose complexities are O(n). And say there’s a 3rd function Z with the following code:

```
void Z(int n){
int i,p=1;
for(i=1;i<=n;i++){
X(n);
if(i==p){
Y(n);
p*=2;
}
}
}
```

Can you help me figure out what the worst-case complexity (Big O) for Z would be in this case?

Also what would the Big O be for Z if X was O(1) and Y was O(n²)?

I’m stumped trying to figure out how the if-statement would affect the calculation in both cases. Any help would be really appreciated. Thanks in advance.