当前位置:网站首页>[Niuke] b-complete square

[Niuke] b-complete square

2022-07-07 01:05:00 *DDL_ GzmBlog

Preface

Use stl Two points , The best subscript is from 0 Let's start
t a g : tag : tag: Two points mathematics
The question :
 Insert picture description here
Ideas :
l ≤ x ≤ r l\le x \le r lxr

l ≤ x ≤ r \sqrt l \le \sqrt x \le \sqrt r lxr

Again because l , r ≤ 1 0 9 l,r\le10^9 l,r109 So we can preprocess out x \sqrt x x Array

Finally, determine the square interval by bisection , The size of the square interval is the answer

code :

int a[N];
int i;

void init(){
    
	Fup(i,1,1e5)a[i] = i;
}

void solve(){
    
	int l,r;cin>>l>>r;
	int n = 1e5;
	
	int L =  lower_bound(a+1,a+1+n,sqrt(l)) - a;
	int R =  upper_bound(a+1,a+1+n,sqrt(r)) - a;
	cout<<max(R-L,0)<<endl;
}

int main(){
    
	init();
	
	int t;cin>>t;while(t--)
    solve();
    return 0 ;
}
原网站

版权声明
本文为[*DDL_ GzmBlog]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/188/202207061714106427.html