Evalute the brackets between 0 and 1.
If n is odd, cos(n+1) = cos(1-n) = 1 = cos(0), hence there's nothing remaining.
On the other hand, 1 + (-1)^n = 1 - 1 = 0, so both formulas do match.
If n is even, cos(n+1) = cos(1-n) = -1, so a_n = (1/2pi) (2/(n+1) + 2/(1-n)) = 2/(pi(1-n^2))
and the other formula ends up with the same value.