Your thought process is correct. You need to replace the j-term with n (n is the largest value of j that can be accepted), but this is probably a typo.
In addition, you can simplify further actions:
n(2*(n(n+1)/2)) 2*n*(n^2+n)/2 n^3+n^2 => O(n^3)
The last step is that the n cubic member will grow much larger than the n square, we can say that it will dominate the execution time for large n. Only another point that I would like to mention is that you should apparently consider the storage p as an operation, as well as two multiplications, although obviously this will not change the simplified long run time.
source share