#C4405. Find the Missing Number in a Sequence
Find the Missing Number in a Sequence
Find the Missing Number in a Sequence
You are given a list of unique integers that represent a sequence of numbers from 1 to n with exactly one number missing. The number n is implicitly defined as the length of the list plus one. Your task is to determine the missing number.
You can calculate the expected sum of all numbers from 1 to n using the formula:
\( S = \frac{n(n+1)}{2} \)
The missing number is the difference between this expected sum and the sum of the given list.
inputFormat
The input is read from standard input (stdin) and has the following format:
- The first line contains an integer k, which is the number of elements in the list.
- The second line contains k space-separated integers representing the elements of the list.
Note: The total number of numbers including the missing number is k+1
.
outputFormat
Output the missing number to standard output (stdout).
## sample7
3 7 1 2 8 4 5
6