1 solutions

  • 0
    @ 2025-11-5 20:17:18

    C :

    #include <stdio.h>
    int count(int n){
      int cnt = n%2?1:0;
      if(n>2) return count(n/2) + cnt + 1;
      if(n==2) return 1;
      return 0;
    }
    int main(){
      int m;
      scanf("%d", &m);
      while(m--){
        int n, i, cnt = 0;
        scanf("%d", &n);
        printf("%d\n", count(n));
      }
      return 0;
    }
    
    • 1

    Information

    ID
    20226
    Time
    3000ms
    Memory
    128MiB
    Difficulty
    (None)
    Tags
    # Submissions
    0
    Accepted
    0
    Uploaded By