fork(2) download
  1. #include <iostream>
  2. #include <math.h>
  3.  
  4. int main() {
  5. int number,divider, mySum, displayed = 0;
  6. std::cin>>number>>divider;
  7.  
  8. mySum = number;
  9.  
  10. do {
  11. int currentCut = 0;
  12.  
  13. while(pow(divider, currentCut) < mySum) {
  14. currentCut++;
  15. }
  16.  
  17. if(currentCut != 0)
  18. currentCut--;
  19.  
  20. if(displayed != 0)
  21. std::cout<<" + ";
  22. else
  23. displayed = 1;
  24.  
  25. std::cout<<divider<<" ^ "<<currentCut;
  26.  
  27. mySum-= pow(divider, currentCut);
  28. } while(mySum != 0);
  29.  
  30. return 0;
  31. }
Success #stdin #stdout 0s 3344KB
stdin
26 5
stdout
5 ^ 2 + 5 ^ 0