Project Euler 135 - Same differences

Official link: https://projecteuler.net/problem=135

Thought Process

Let x = a + d, y = a, z = a - d.

Then x^2 - y^2 - z^2 = a(4d - a) = n

This means with a given a we have that 4d - a > 0 => d > floor(a/4) and 0 < z = a - d => a > d, therefore we have floor(a/4) < d < a

This means we can simply create an array = [0]*10^6, and store the number of solutions each n has, for example array[27] = 2. Then we loop through a from 1 to 10^6 and correspondingly d, and at the end count the number of n that have 10 solutions!

Although if you try this without any safety stopper it will take a while (Hint: Stop checking if n goes over 10^6)

Interactive Code

Enter a number (yourinput)

Code will output the number of n less than yourinput that have exactly ten distinct solutions