提交时间:2024-08-20 22:12:31

运行 ID: 173618

#include<bits/stdc++.h> using namespace std; char getOneBit(int a) { int b=2; int count=0,count1=0; int arr[100]; do { arr[count++]=a%b; if(a%b==1) count1++; a=a/b; } while(a!=0); return count1>count/2?'A':'B'; } int main() { int a,b; cin>>a>>b; int cnt1=0,cnt2=0; for(int i=a;i<=b;i++) { char res = getOneBit(i); res=='A'?cnt1++:cnt2++; } cout<<cnt1<<' '<<cnt2; }