#include <iostream>
#include <cmath>
using namespace std;

int main() {
    int n;
    cin >> n;
    int l, r;
    while (n--) {
        cin >> l >> r;
        int start = ceil(sqrt(l)); // Start from the square root of l
        int end = floor(sqrt(r));  // End at the square root of r
        int count = 0;
        for (int j = start; j <= end; j++) {
            count++;
        }
        cout << count << "\n";
    }
}
  1. 如果 l 不是完全平方数,则其平方根将是分数。在这种情况下,您需要从下一个大于该小数值的整数开始计数,因为所有小于该小数值的数字在平方时都会低于 l 。 ceil 函数正是这样做的——它向上舍入到最接近的整数。

  2. 如果 r 不是完全平方数,则其平方根将是分数。在这种情况下,您需要以小于该小数值的最大整数结束计数,因为任何大于该分数的数字在平方时都会超过 r 。 floor 函数执行此操作 - 它向下舍入到最接近的整数。