Time Complexity of given code snippet

void function(int n)
{
int count = 0;

     for (int i=0; i<n; i++) 
     for (int j=i; j< i*i; j++) 
         if (j%i == 0) 
         { 
            for (int k=0; k<j; k++) 
                 printf("*"); 
          } 
    } 

How is the time complexity here O(N^5) ?

Let us calculate the no of iterations for a particular value of i = i. Note that the innermost nested loop always runs because the if condition is always true. How ? Since j runs from i to i * i, every number from in this range is of the form i * a , where a ranges from 1 to i, so each number is divisible by i.

Now, for a particular value of i, the no. of iterations equal Σ (i*i - i). This is of the order of O(i^3). You can work this out yourself using basic maths formulae. Now, total complexity is :- Σ i * i^3. This is of the order of O(n^5).