#include using ll = std::int64_t; int main(){ std::cin.tie(nullptr); std::ios::sync_with_stdio(false); int T; std::cin >> T; for(int _=0;_> A >> B; int res = 0; int q1 = A / B; int l1 = A / (q1 + 1); int q2 = 1; int l2 = B / (q2 + 1); int r = B; while(true){ int l = std::max(l1, l2); if(q1 < q2){ res += std::max(r - std::max(l, (B - A + q2 - q1 - 1) / (q2 - q1) - 1), 0); } if(l == 0){break;} r = l; q1 = A / l; l1 = A / (q1 + 1); q2 = B / l; l2 = B / (q2 + 1); } std::cout << res << std::endl; } }