Comment

avatar username

For i = 0, you can calculate all valid j(ignoring k for now) in O(n^2). The number of valid j can be called val_j.

Note that if i = 1, each valid j is also incremented by one. Therefore, the total number of valid (i,j) pairs is n*val_j since i can be any value and there will always be the same number of valid j.

Next, we can repeat this logic with j and k. For a given j, the number of valid k is val_k and can be calculated in O(n^2).

The number of total valid j is the number of valid (i,j) pairs which were calculated above, so the answer is n*val_j*val_k.

The actual rating of this user is 1476.

Original comment.

Statistics