Solution to problem 39.

brute-force takes ~ 2.0 seconds where n <= 1000
Solution to problem 40.

liberal use of Math.Log10 speeds this up a lot (and avoids use of
strings).