Given all numbers between 1 and n except one, find the missing number.
n * (n + 1) / 2.
- Math
- Prefix Sum
#include <bits/stdc++.h> using namespace std; int main() { long long n; cin >> n; long long sum = n * (n + 1) / 2; for (int i = 0; i < n - 1; i++) { long long x; cin >> x; sum -= x; } cout << sum << "\n"; return 0; }