problem 482. Was able to get correct sample answer, but need to refactor so that it can run larger numbers.