Forth problem from ProjectEuler