来自大佬usx21145328链接
#include <stdio.h> #include<math.h> long Erjin(long n, int* arr) { int i = 0, num = 0; while (n) { arr[i] = n % 2; n /= 2; if (arr[i] == 1) num++; i++; } return num; } int main() { long t; scanf("%ld", &t); for (long i = 0; i < t; i++) { long n; int arr[25] = {0}; scanf("%ld", &n); long num = Erjin(n, arr); printf("%ld %ld\n", num, (long)pow(2, num) - 1); } return 0; }