1008.月之数
题意为,求出二进制数位数为n的数的个数。由于1<=n<=20,由于数据范围很小,暴力预处理出来,然后输出答案即可。
#include<cstdio>
#include<cstring>
const int maxn=100;
int f[maxn];
int main()
{
memset(f,0,sizeof(f));
int ans=0,now=0;
while (ans<=20)
{
ans=0;
int st=now,w=0;
while (st>0)
{
ans++;
if (st&1) w++;
st>>=1;
}
if (ans>20) break;
f[ans]+=w;
now++;
}
int t;
scanf("%d",&t);
while (t--)
{
int n;
scanf("%d",&n);
printf("%d\n",f[n]);
}
return 0;
}