目测发现ans=x-bitcount(x)
#include<bits/stdc++.h> using namespace std; int T,n,x; signed main () { scanf("%d",&T); while (T--) { scanf("%d",&n);x=n; while (x) { n--; x-=x&-x; } printf("%d\n",n); } return 0; }
目测发现ans=x-bitcount(x)
#include<bits/stdc++.h> using namespace std; int T,n,x; signed main () { scanf("%d",&T); while (T--) { scanf("%d",&n);x=n; while (x) { n--; x-=x&-x; } printf("%d\n",n); } return 0; }
转载于:https://www.cnblogs.com/rrsb/p/9867212.html