[Solved] How to get the n if I know the result of 1+2+3+..+n=n*(n+1)/2? [duplicate]


Only by addition and subtraction
Simply add numbers from 1 and check whether the sum is the given number.

In pseudocode.
Given 5050.

number := 5050
next, sum := 0
while sum <= number
  next := next + 1
  sum := sum + next
return next

3

solved How to get the n if I know the result of 1+2+3+..+n=n*(n+1)/2? [duplicate]