Start by using the trig formula . That gives

You can sum the cosine series using (geometric series).

I'll leave it to you to take it from there. I haven't tried to complete the calculation, but my gut feeling is to be suspicious of the claimed result. I would expect the answer to depend on whether and 2p have a nontrivial common divisor, rather than whether they are divisible by 2p. But I may well be wrong about that.