Problem16: Beta solution without using a library for big numbers