SuperFunction

Can someone please explain the logic for (for SUBTASK 3 AND 4) http://www.codechef.com/LTIME07/problems/SFUNC of this question?! I m unable to get the same form editorial.

//