fork download
  1. #include <iostream>
  2. #include <math.h>
  3. using namespace std;
  4.  
  5. int main() {
  6. // your code goes here
  7. int a, b, arr[17], temp[17];
  8. cin>>a; b=a;
  9. for(int i=0; i<17; i++) {
  10. arr[i]=pow(2, i);
  11. }
  12. for(int j=16; b>0; j--) {
  13. while(b>=arr[j]) {
  14. temp[j]=log2(arr[j]); b=b-arr[j];
  15. cout<<temp[j]<<" "<<arr[j]<<" "<<b<<endl;
  16. }
  17. }
  18. return 0;
  19. }
Success #stdin #stdout 0s 3300KB
stdin
16385
stdout
14 16384 1
0 1 0