• + 2 comments

    I'll try to explain with an example: Lets say you have four countries with amount of A, B, C and D people respectively. Now we should calculate the number of posible pairs from different countries. The order does't matter so the calculation would be:

    A*B + A*C + A*D + B*C + B*D + C*D = A*B + (A+B)*C + (A+B+C)*D

    From that pattern it is easy to see the solution proposed above.