I'm facing an informatics problem, math based.
Having this series:
1, 1, 2, 1, 2, 3, 1, 2, 3, 4, 1, 2, 3, 4, 5 ....
i have to efficiently find the value of element from position K;
for example, on position k = 5, element has the value 2
the way to solve this is to solve a square equation like this:
x^2 - x - 2*i
where i stands from k-1 to 1 and we downgrade k until we find a solution which satisfies this:
- one root of the equation is
higher than 0 - it's a natural number
and the value of that element on position k will be k-i
i did that on C++ and works 100%, with help from a friend;
for example, when k = 5 and our i iterator gets the value 3, the equation will be:
x^2 - x - 6
with positive root x1 = 3
and in final, the solution will be k-i -> 5-3 which is clearly 2, the value of the element from position K
i am trying to understand this for hours, but i dont get why the solution of that equation gives us the value from position K
if anybody knows the answer, i'm waiting for it!
Thanks!