#C13696. Find the Missing Number
Find the Missing Number
Find the Missing Number
You are given an integer n
which represents the total count of numbers from 1 to n. You are also provided with n-1
numbers in random order, representing all the numbers from 1 to n except one missing number. Your task is to find the missing number.
Recall that the sum of the first n natural numbers is given by the formula: \( S = \frac{n(n+1)}{2} \). Use this property to determine the missing number.
Example:
Input: 5 1 2 4 5</p>Output: 3
inputFormat
The input is given via stdin
and consists of two lines.
- The first line contains a single integer
n
, representing the total count of numbers if none were missing. - The second line contains
n-1
space-separated integers.
It is guaranteed that the numbers are unique and between 1 and n (inclusive) except for one missing number.
outputFormat
Output the missing number via stdout
as a single integer.
5
1 2 4 5
3