The topmost floor has only 1 apartment so the one below has 2 apartments, the one below has 4 apartments, the one below that has 8 etc.
This is a geometric sequence: 1, 2, 4, 8, 16, 32, 64.
One approach to this problem would be to simply add all those numbers:
The other approach (which is especially good for large numbers and long sequences) is to use formula for sum of the first `n` terms of geometric series.
`S=a(1-r^n)/(1-r),` `r ne 1`
where `a` is the first term and `r` is the common ratio of the series.
In this case `a=1` and `r=2,` hence we have
The result is, of course, the same. There are 127 apartments in the building.