Let the total number of balls in the equilateral triangle be n.
Let the number of rows in the triangle be x.
When the balls are arranged in the form of an equilateral triangle, each row will have balls equal to the row number, i.e, the first row will have 1 ball, second will have 2 balls and so on. This forms an AP.
So, the total number of balls will be sum of AP, i.e, 1+2+3+4+........+x.
So, n=x(x+1)/2
n=(x^2+x)/2 ......... (eq 1)
Next, 669 balls are added to the existing number of balls, it becomes possible to arrange all the balls in the form of a square.
Also, as per the given information, the numebr of balls in each side of the square becomes 8 less than number of balls in each side of the triangle.
So, now each side of the square has (x-8) balls and the total number of balls is (n+669).
So, (x-8)(x-8)=(n+669)
(x^2-16x+64) = (n+669) .......(eq 2)
Solving (eq 1) and (eq 2), we get
x^2-33x-1210=0.
Solving the above quadratic equation, we get x=55 (which is the only positive solution of the equation).
Replacing x=55 in (eq 1), we get n=1540. which is the required number of balls in the equilateral triangle.
Answer is 1540.