The ? 1 ? 2 ? ... ? n = k problem |
Given the following formula, one can set operators '+' or '-' instead of each '?', in order to obtain a given k
? 1 ? 2 ? ... ? n = k
For example: to obtain k = 12 , the expression to be used will be:
- 1 + 2 + 3 + 4 + 5 + 6 - 7 = 12
with n = 7
Input contains integer k (0<=|k|<=1000000000).
Your program should print the minimal possible n (1<=n) to obtain k with the above formula
12
7
-3646397
2701