The second term can be expanded to $$ 2*|a_k|(\frac{ e^{i(2\pi*f_k*t+a_k)} + e^{-i(2\pi*f_k*t+a_k)}}{2}) $$
$$= |a_k|e^{ia_k}e^{i(2\pi*f_k*t)}+|a_k|e^{-ia_k}e^{-i(2\pi*f_k*t)}$$
$$= a_ke^{ia_k}e^{i(2\pi*f_k*t)}+a_k^*e^{-ia_k}e^{-i(2\pi*f_k*t)}$$
Since $a_k=|a_k|e^{ia_k}$ and $a_k^*=|a_k|e^{-ia_k}$ and $cos\theta=\frac{ e^{i\theta} + e^{-i\theta}}{2}$