fork download
  1. #include <cstdio>
  2. #include <vector>
  3.  
  4. using namespace std;
  5.  
  6. const char* letters = "abcdefghijklmnoprstuxy";
  7.  
  8. void printDecomposition(int n)
  9. {
  10. bool first = true;
  11. printf("%d = (", n);
  12. int i = 0;
  13. while (n)
  14. {
  15. if (n % 2 == 1)
  16. {
  17. if (first)
  18. {
  19. printf("%c", letters[i]);
  20. first = false;
  21. }
  22. else
  23. {
  24. printf(" + %c", letters[i]);
  25. }
  26. }
  27. n /= 2;
  28. i++;
  29. }
  30. printf(");\n");
  31. }
  32.  
  33. int main()
  34. {
  35. int d;
  36. while (scanf("%d", &d) == 1)
  37. {
  38. printDecomposition(d);
  39. }
  40. return 0;
  41. }
Success #stdin #stdout 0s 2856KB
stdin
20
1
2
3
4
6
9
11
stdout
20 = (c + e);
1 = (a);
2 = (b);
3 = (a + b);
4 = (c);
6 = (b + c);
9 = (a + d);
11 = (a + b + d);