var | desc |
---|---|
Range |
As an input we get
The formula to get the sum of a range of increasing natural numbers is:
So to find the missing number all we have to do is to find out the sum of the range with above formula, and then subtracting the sum of the given integers (second input).
In Rust 🦀 code:
fn main() {
let mut l = std::io::stdin().lines().take(2);
let (f, s) = (l.next().unwrap(), l.next().unwrap());
let n: u64 = f.unwrap().parse().unwrap();
let sum: u64 = s
.unwrap()
.split_whitespace()
.map(|n| n.parse::<u64>().unwrap())
.sum();
println!("{}", n * (n + 1) / 2 - sum);
}