For a given i, How many times if ( j % i == 0) is true?
(For a given i), j can take the value 1, 2, 3, ....... (i * i).
So, whenever j take the value i, 2i, 3i, ..... (i*i). The condition if ( j % i == 0) is true.
So, for a given i, the condition if ( j % i == 0) is true for exactly i times. (Important).
Whenever the condition (if) is true how many times the innermost loop will execute?
For a given i, j can take the value 1, 2, 3, ....... (i * i). (As mentioned above).
when j = i, the if condition is true, And the innermost loop will run i times.
when j = 2i, the if condition is true, And the innermost loop will run 2i times.
And so on,
When j = i * i, the if condition is true, And the innermost loop will run i*i times.
Therefore, for a given i, the innermost loop will run for ( i + 2i + 3i + 4i + ....... + i*i) times.
And i will vary from i = 1 to n.
$\Rightarrow$ T(n) = $\sum_{i = 1}^{n} (i + 2i + 3i +..... (i*i))$
T(n) = $\sum_{i = 1}^{n} i*(1 + 2 + 3 + ...... i))$
T(n) = O($n^{4}$)