Given a positive integer n, find the pivot integer x such that the sum of all numbers from 1 to x inclusive equals the sum of all numbers from x to n inclusive. Return x, or -1 if no such integer exists. For any input there is at most one pivot.
Given a positive integer n, find the pivot integer x such that the sum of all numbers from 1 to x inclusive equals the sum of all numbers from x to n inclusive. Return x, or -1 if no such integer exists. For any input there is at most one pivot.
Example 1:
Input: {"n":8}
Output: 6
Constraints:
1≤n≤1000
Test Cases
Input (Stdin)
Expected Output (Stdout)
Execution Result
Run code to see results.
Input
arr ={"n":8}
Find x in 1..8 where 1 + ... + x equals x + ... + 8; both sides include x itself.