fork download
  1. #include <iostream>
  2. #include <math.h>
  3.  
  4.  
  5. using namespace std;
  6.  
  7. int main()
  8. {
  9. int x=0,n,i,z;
  10. int tab[20];
  11. cin>>n;
  12. z=n;
  13.  
  14. while(z>2)
  15. {
  16. z=z/2;
  17. x++;
  18. }
  19. tab[0]=x;
  20.  
  21. cout << n-pow(2,x) << endl;
  22. int suma;
  23. suma=n-pow(2,x);
  24.  
  25.  
  26. for (int i=1; suma>2; i++)
  27. {
  28. int z=0;
  29. int pomocnicza;
  30. pomocnicza=suma;
  31. while (pomocnicza > 2)
  32. {
  33. pomocnicza/=2;
  34. z++;
  35.  
  36.  
  37.  
  38.  
  39. }
  40. tab[0+i]=z;
  41. suma=n-pow(2,x-i);
  42. }
  43.  
  44. for(x; x>0; x--)
  45. {
  46. int f=x;
  47. for (int i=0; i<f; i++)
  48. cout<<"2^"<<tab[x-i]<<" + ";
  49. }
  50. return 0;
  51. }
  52.  
Runtime error #stdin #stdout 0s 3472KB
stdin
Standard input is empty
stdout
8.98683e+08