Problem 104 from Project Euler, written in Java