Number of iterations until incremental sum = x

58 Views Asked by At

It costs \$50 for 1 token each token I buy increases the cost by \$50 how many tokens can I buy if I have \$10,000?

I'm trying to code a formula for this but can't figure it out without just using a loop.

1

There are 1 best solutions below

1
On BEST ANSWER

Suppose $a_1=50$. Then $$a_2=a_1+50, a_3=a_2+ 50 ,...$$ or else $$a_n=a_1+(n-1)50=50+(n-1)50=50n$$ Then the sum of the first n numbers of the sequence is: $$S=a_1+a_2+a_3+...+a_n=50+2\cdot 50+ 3\cdot 50+ ...+ 50n=50(1+2+3+...+n)=50\frac{n(n+1)}{2}=25n(n+1)$$

So in our problem: $$S=10000\Rightarrow 25n(n+1)=10000\Rightarrow n^2 +n= 400 \Rightarrow n^2+n-400=0$$ Which has no natural numbers as root. So from here you must find a final cost that is very near to 10000 and give integer roots to the above equation.