PROBLEM LINK:
Author:Konstantin Sokol
Tester:Gerald Agapov
Editorialist:Tasnim Imran Sunny
DIFFICULTY:
Cakewalk
PREREQUISITES:
Simple Math
PROBLEM:
Given a list of N integers check if their sum is the same as the sum of first N natural numbers.
EXPLANATION:
The required stamp division is possible if:
C1 + … + CN = 1 + 2 + … + N
There’s a very common formula for the sum of first N natural numbers that is: 1 + 2 + … + N = N*(N+1)/2. (Proof)
So just compute the sum of all the numbers and check if the sum is N*(N+1)/2. Be careful of overflow, use 64 bit integers for computing the sum.
AUTHOR'S AND TESTER'S SOLUTIONS:
Author's solution can be found here.
Tester's solution can be found here.