fork(1) download
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. unsigned long long F[21];
  6. int M, N;
  7. bool f = true;
  8. int k[1005];
  9.  
  10. void D(int m, int n, int d) {
  11. if (m == 1) {
  12. k[d] = n;
  13. unsigned long long c = F[N];
  14. for (int i = 0; i <= d; ++i) c /= F[k[i]];
  15. if (!f) cout << " + ";
  16. f = false;
  17. if (c > 1 || !N) cout << c;
  18. for (int i = 0; i <= d; ++i) {
  19. if (k[i]) {
  20. cout << "x" << (i + 1);
  21. if (k[i] > 1) cout << "^" << k[i];
  22. }
  23. }
  24. return;
  25. }
  26. for (int i = n; i >= 0; --i) {
  27. k[d] = i;
  28. D(m - 1, n - i, d + 1);
  29. }
  30. }
  31.  
  32. int main() {
  33. ios_base::sync_with_stdio(false);
  34. cin.tie(NULL);
  35. F[0] = 1;
  36. for (int i = 1; i <= 20; ++i) F[i] = F[i - 1] * i;
  37. if (cin >> M >> N && M > 0 && N >= 0 && N <= 20) {
  38. D(M, N, 0);
  39. cout << '\n';
  40. }
  41. return 0;
  42. }
Success #stdin #stdout 0s 5320KB
stdin
Standard input is empty
stdout
Standard output is empty