aimon1337

hamming

Feb 14th, 2021 (edited)
354
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.61 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3. #define min(a,b) ((a) < (b) ? (a) : (b))
  4. void generare(int n)
  5. {
  6.     int t[n];
  7.     int i2 = 0, i3 = 0, i5 = 0;
  8.     int m2 = 2;
  9.     int m3 = 3;
  10.     int m5 = 5;
  11.     int urmator = 1;
  12.  
  13.     t[0] = 1;
  14.     cout<<t[0]<<" ";
  15.     for (int i = 1; i < n; i++) {
  16.         urmator = min(m2,min(m3, m5));
  17.         t[i] = urmator;
  18.         if (urmator == m2) {
  19.             i2 = i2 + 1;
  20.             m2 = t[i2] * 2;
  21.         }
  22.         if (urmator == m3) {
  23.             i3 = i3 + 1;
  24.             m3 = t[i3] * 3;
  25.         }
  26.         if (urmator == m5) {
  27.             i5 = i5 + 1;
  28.             m5 = t[i5] * 5;
  29.         }
  30.         cout<<t[i]<<" ";
  31.     }
  32. }
  33. int main()
  34. {
  35.     int n; cin>>n;
  36.     generare(n);
  37.     return 0;
  38. }
  39.  
Add Comment
Please, Sign In to add comment