Two sum algorithm variant
There is no need to iterate over the range. Consider a pseudocode:

sort numbers from the input file into an array A
N = size of collection
result = 0
for i in [0..N)
    find largest j (j &gt; i) such that A[i] + A[j] &lt; start
    find smallest k (k &gt; i) such that A[i] + A[k] &gt; finish
    result += k - j


Each find is \$O(\log N)\$ at worst. Overall complexity is \$O(N \log N)\$ regardless of the target range.