If I have n-r
numbers, from 1 to n
where r
numbers are missing in between, then how can I calculate all possible numbers that can be formed from addition of these numbers (either in groups of 2/3/4/5/6...).
For example, lets say I have 5-2
numbers,
that is, 1 2 4
and 3 5
are missing. Now, I can form
1 - {1}
2 - {2}
3 - {1,2}
4 - {4}
5 - {1,4}
6 - {4,2}
7 - {1,2,4}
8 - Cannot be formed
This is I need to find out, that is the first number from 1 which I cannot form using the combination of the given digits. A simple logic would do fine. Thanks!