If you know the result of 1+2+3+..+n
, which is n*(n+1)/2
.
For example, if the result is 5050
, then I can know n
is 100
. How can I obtain the n
. However, you can only calculate the n
by only addition and substraction.
And I know how I can get the n
i is that I can traverse the natural number from 1 to n, by computing per different 1+2+3+...+n
, like 1
, 1+2
, 1+2+3
,...1+2+..+n
, then I can check every result to 5050
, then I can find the n
is 100
. But I find that the calculating steps will over 2000 steps, so there is a good algorithm to find the n
?
Thanks!.