Computing the periods of preimages in surjective cellular automata