I'm not able to comeup with solution in given constraints.
More formally:
You are given l and r where r can be upto 10^12 . you need to return the count of no of pairs such that sqrt(a^2-b) is integral where b lies between l and r (both l and r are inclusive).