SPOJ BABTWR

My solution to the problem "Tower of Babylon" on SPOJ. (Problem code:
BABTWR)