Advertisement
STANAANDREY

1/22 cls

Oct 20th, 2020
2,025
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.83 KB | None | 0 0
  1. #include<iostream>
  2. #include<fstream>
  3. using namespace std;
  4. int st[27], n, m, x, divs[27];
  5. ofstream fout("sir.out");
  6.  
  7. void tipar(int k)
  8. {
  9.     for (int i = 1; i <= k; i++)
  10.         fout << divs[st[i]] << ' ';
  11.     fout << endl;
  12. }
  13.  
  14. int solutie(int k)
  15. {
  16.     return k == m;
  17. }
  18.  
  19. void bktr()
  20. {
  21.     int k = 1;
  22.     st[k] = 0;
  23.     while (k)
  24.     {
  25.         if (st[k] < n)
  26.         {
  27.             st[k]++;
  28.             if (solutie(k))
  29.                 tipar(k);
  30.             else
  31.             {
  32.                 k++;
  33.                 st[k] = st[k - 1];
  34.             }
  35.         }
  36.         else
  37.             k--;
  38.     }
  39. }
  40.  
  41. void getDivs() {
  42.     for (int d = 1; d <= x / 2; d++)
  43.         if (x % d == 0)
  44.             divs[++n] = d;
  45.     divs[++n] = x;
  46. }
  47.  
  48. int main ()
  49. {
  50.     cin >> m >> x;
  51.     getDivs();
  52.     bktr();
  53.     return 0;
  54. }
  55.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement