提交时间:2024-04-09 19:22:30

运行 ID: 45079

#include<bits/stdc++.h> using namespace std; int a[40],cnt,c; void f(int n){ memset(a,a+cnt,0); cnt=0; stack<int> st; while(n){ st.push(n%2); n/=2; } while(st.empty()==0){ a[cnt++]=st.top(); st.pop(); } return ; } int main(){ int l,r; cin>>l>>r; for(int i=l;i<=r;i++){ f(i); for(int j=0;j<cnt;j++){ if(a[j]==1) c++; } } cout<<c; return 0; }