若将一个正整数化为二进制数,在此二进制数中,我们将数字1的个数多于数字0的个数的这类二进制数称为A类数,否则就称其为B类数。
例如:(13)10=(1101)2
其中1的个数为3, 0的个数为1,则称此数为A类数
(10)10=(1010)2
其中1的个数为2,0的个数也为2,称此数为B类数
(24)10=(11000)2
其中1的个数为2,0的个数为3,则称此数为B类数
输入格式
一个整数n (n<=10000)
输出格式
1~n范围内A类数的个数和B类数的个数
输入/输出例子1
输入:
1000
输出:
538 462
#include<bits/stdc++.h>
using namespace std;
int n;
int A=0,B=0;
int main(){
cin>>n;
for(int i=1;i<=n;i++){
int sum1=0;
int sum0=0;
int temp=i;
for(;temp>0;){
int x=temp%2;
if(x==1) sum1++;
else sum0++;
temp=temp/2;
}
if(sum1>sum0) A++;
else B++;
}
cout<<A<<" "<<B;
return 0;
}