2 条题解

  • 0
    @ 2026-3-12 19:16:27

    正确的写法是位运算~~ 左移即可

    #include <bits/stdc++.h>
    using namespace std;
    #define faster ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)
    typedef long long ll; ll n;ll cntl,cnta;const ll N=1e3+5; 
    ll a[N]; ll T=1;
    void solve(){
    	ll l,r;cin>>l>>r;
    	ll x=1;
    	while(x<=r){
    		if(x>=l)cntl++;
    		x=x<<1;
    	}
    	 cout<<cntl;
    }
    int main(){
    	faster;
    	while(T--)solve();
    	return 0;
    }
    
    
    • 0
      @ 2025-5-7 20:11:41

      打表+二分即可

      #include <bits/stdc++.h>
      using namespace std;
      #define faster ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)
      typedef long long ll; ll n;
      vector<ll>v={1,2,4,8,16,32,64,128,256,512,1024,2048,4096,8192,16384,32768,65536,131072,262144,524288,1048576,2097152,4194304,8388608,16777216};
      ll cntl,cnta,ans; 
      
      void solve(){
      	ll r,l;
      	cin>>l>>r;
      	auto pos_l=lower_bound(v.begin(),v.end(),l); 
      	auto pos_r=upper_bound(v.begin(),v.end(),r);
      	ll len=pos_r-pos_l;
      	cout<<len;
      }
      int main(){
      	faster;
      	ll T=1;
      	while(T--)solve();
      	return 0;
      }
      
      • 1

      信息

      ID
      96
      时间
      1000ms
      内存
      256MiB
      难度
      2
      标签
      递交数
      68
      已通过
      38
      上传者