Maths Question/ Ad Hoc

http://code.google.com/codejam/contest/4254486/dashboard#s=p1