This code counts pairs of positions:
count = 0
for i in range(n):
for j in range(i + 1, n):
count += 1
Implement count_pairs(n) so it returns the final value of count.
n can be huge, so you cannot run the loops. Work the number out from the shape of the loops.
Example 1
Input:
count_pairs(4)
Output:
6
The pairs are (0,1) (0,2) (0,3) (1,2) (1,3) (2,3).
Example 2
Input:
count_pairs(1)
Output:
0
No pair fits.
0 <= n <= 10**12n.No results yet
Run your code to check it against the examples, or submit to run every test.