Counting cycles in permutations by group characters, with an application to a topological problem