Faster solution for problem004.