johnny and beanstalk

can anybody explain the question and approach for this question…
http://www.codechef.com/problems/MARCHA2

got it…
http://www.codechef.com/viewsolution/7267090