题意:
解法:
由于数据只到1e9,sqrt(1e9)=1e3,预处理所有完全平方数,
对于[l,r],两次二分找到范围内有多少个数即可.
注意l可能为0,同时0也是完全平方数.
code:
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int maxm=2e6+5;
vector<int>temp;
void init(){
for(int i=0;i*i<=1e9;i++){
temp.push_back(i*i);
}
}
signed main(){
ios::sync_with_stdio(0);cin.tie(0);
init();
int T;cin>>T;
while(T--){
int l,r;cin>>l>>r;
int ans=upper_bound(temp.begin(),temp.end(),r)-
lower_bound(temp.begin(),temp.end(),l);
cout<<ans<<endl;
}
return 0;
}