Partial solution for Divide the Tangerine problem - http://www.codechef.com/APRIL14/problems/TANGDIV