If is the side length of the triangle, then to completely fill it,
balls are required.
Suppose there are balls available. To find the maximum possible , solve the equation
and round the non-negative root down to the nearest integer.
Solve the quadratic equation:
The answer will be \lfloor(-1 + \sqrt{1 + 8k}) / 2 \rfloor.
Algorithm implementation
Read the value of .
scanf("%d",&k);Compute and print the answer.
n = int((-1 + sqrt(1.0 + 8*k)) / 2.0);
printf("%d\n",n);