Try to use Dot product rule.which is
$$\vec A. \vec B=|\vec A|.|\vec B|.cos \theta $$
Here,
$$\vec A= \hat i + 2\hat j,\vec B=4\hat i + p\hat k$$$$|\vec A|=\sqrt{1^2+2^2}=\sqrt{5}~~,~~|\vec B|=\sqrt{16+p^2}$$$$\theta=\cos^{-1}(\frac{1}{5})$$
If you substitute everything in the formula I think you will get, $$p=\pm 8$$
HINT:
Try to use Dot product rule.which is $$\vec A. \vec B=|\vec A|.|\vec B|.cos \theta $$ Here, $$\vec A= \hat i + 2\hat j,\vec B=4\hat i + p\hat k$$ $$|\vec A|=\sqrt{1^2+2^2}=\sqrt{5}~~,~~|\vec B|=\sqrt{16+p^2}$$ $$\theta=\cos^{-1}(\frac{1}{5})$$
If you substitute everything in the formula I think you will get, $$p=\pm 8$$