借鉴了榜二的思路,很赞
排列与二进制
https://www.nowcoder.com/practice/647fc23dc4e147328cc484e3aeb6cc2a
#include <stdio.h> int main(){ int n,m,a[100]; while(scanf("%d%d",&n,&m)!=EOF){ if(n==0)return 0; int sum=0; for(int i=n-m+1;i<=n;i++){ int k=i; while(k%2==0){ k/=2; sum++; } } printf("%d\n",sum); } return 0; }