There is the dependency in the 3rd, inner loop to the variable p so try with the normal approach.
for i = n | for i = n / 2 | ...............
j = 1, 2,3..........n-1 | j = 1, 2,..........n/2 -1 | ............
each time p is incremented so | after completion of 2nd loop |....................
after completion of the 2nd loop p = n | p = n/2 |..................
Now 3rd loop will execute |Now 3rd loop will execute |................
log (n) Base 3 time | log (n/2) Base 3 time |..................
so finally if you add all log(n) + log(n/2) + log(n / (2^2) ) + .....................log (n / (2 ^ log (n) Base 2) )
= O( (log (n) Base 3) * (log (n) Base 2) )
= O(log (n) ^ 2)