#APL(NARS), 15 chars, 30 bytes

    {+/∊(⍵⍴2)⊤⍺..⍵}

test

      f←{+/∊(⍵⍴2)⊤⍺..⍵}
      1000 f 2000
    5938
This seems ok even in the case 0 f 0 because +/⍬ is 0.