Given a set S of n natural numbers below 9n/7, how can one establish the number of pairs summing to every number from 0 to 18n/7? (2-combinations, 3 < n)
Let m be the maximum value of elements in S.
If m was n-1, the sequence of counts of pairs summing up to ( 0, 1, … 18n/7 ) would be [ 0, 1, 1, 2, 2, … m/2, m/2, (m+2)/2, m/2, m/2, (m-2)/2, … 2, 1, 1, 0, …, 0 ] for odd n, or [ 0, 1, 1, 2, … (n-2)/2, (n-2)/2, n/2, n/2, n/2, (n-2)/2, (n-2)/2, (n-4)/2, … 2, 1, 1, 0, …, 0 ] for even n.
It isn't too difficult to establish the counts if n is an element of S (and one of the numbers below isn't), as is nesting two loops and just counting the occurrences of each sum - Ο(n²):
How can one establish a histogram of pair sums (much) faster than Ο(n²)?
(Does knowing m < 9n/7 help?
Is it notably harder for 9n/2 < m ((semi-)sparse set)?)