Topcoder IntegerGenerator - beautiful solution