思维题
对l开根号之后向上取整,对r开根号向下取整,求数量即可,可以带个数进去。康康要不要加一减一。
#include <bits/stdc++.h> using namespace std; #define js ios::sync_with_stdio(false);cin.tie(0); cout.tie(0) typedef long long ll; inline int read() { int s = 0, w = 1; char ch = getchar(); while (ch < 48 || ch > 57) { if (ch == '-') w = -1; ch = getchar(); } while (ch >= 48 && ch <= 57) s = (s << 1) + (s << 3) + (ch ^ 48), ch = getchar(); return s * w; } int main() { int T = read(); while (T--) { int l = read(), r = read(); int ans = floor(sqrt(r))- ceil(sqrt(l)) + 1; printf("%d\n", ans); } return 0; }