Exact solution for quantum dynamics of a periodically driven two-level system