Modify algorithm to take a specified number of digits for the output number.