Updated solution to work with numbers up to the trillions