原題鏈接
這個OJ的int不是32位的,所以坑了不少人,換成unsigned long long就行了。
#includeint main(){ unsigned long long t, n, a, b, d, i, j, oka; scanf("%lld", &t); while(t--){ scanf("%lld", &n); oka = b = d = 0; a = i = 1; for(j = 1; j <= 32; ++j){ if(n & i){ if(!oka) oka = 1; ++d; b = 0; }else{ if(!oka) ++a; //c == a - 1; ++b; } i <<= 1; } printf("%lld %lld %lld %lld\n", a, b, a - 1, d); } return 0; }