Patey

Untitled

May 6th, 2021
554
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include<stdlib.h>
  2. #include<stdio.h>
  3. #include<math.h>
  4.  
  5. int main()
  6. {
  7.     int n, i,m,nr=0;
  8.     FILE *fis_in, *fis_out;
  9.  
  10.     fis_in = fopen("in.txt", "rt");
  11.     fis_out = fopen("out.txt", "wt");
  12.     fscanf(fis_in, "%d", &n);
  13.  
  14.     for (i = 31; i >= 0; i--)
  15.     {
  16.         if ((n >> i) & 1)
  17.             break;
  18.     }
  19.  
  20.     i--;
  21.     for (; i >= 0; i--)
  22.     {
  23.         if ((n >> i) & 1)
  24.             nr += i;
  25.         else
  26.             nr += i+1;
  27.     }
  28.     fprintf(fis_out,"%d", nr);
  29. }
RAW Paste Data