To find for large , you cannot simulate steps. That takes time. If , you time out.
Instead, precompute for all and all . You can reach any -th successor by combining powers of . This is binary decomposition. This is binary lifting. It reduces to per query after preprocessing. The preprocessing pays off when you have multiple queries.
Space complexity is for the data structures used.