Euler Solution to Problem 1 in JS