Note that there can be at most different numbers among . Indeed, if there are at least distinct elements there, their sum is at least 0 + 1 + \ldots + 6326 = 20005975 > 20000000.
So, for every element of count — the number of times it appears in , for every element of count — the number of times it appears in , and for each such pair add to the answer cnt[x]cnt[y]\lfloor \sqrt{|a_i - b_j|} \rfloor
This works in O(n+m+\sqrt{sumA}\sqrt{sumB}).