Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- #define min(a,b) ((a) < (b) ? (a) : (b))
- void generare(int n)
- {
- int t[n];
- int i2 = 0, i3 = 0, i5 = 0;
- int m2 = 2;
- int m3 = 3;
- int m5 = 5;
- int urmator = 1;
- t[0] = 1;
- cout<<t[0]<<" ";
- for (int i = 1; i < n; i++) {
- urmator = min(m2,min(m3, m5));
- t[i] = urmator;
- if (urmator == m2) {
- i2 = i2 + 1;
- m2 = t[i2] * 2;
- }
- if (urmator == m3) {
- i3 = i3 + 1;
- m3 = t[i3] * 3;
- }
- if (urmator == m5) {
- i5 = i5 + 1;
- m5 = t[i5] * 5;
- }
- cout<<t[i]<<" ";
- }
- }
- int main()
- {
- int n; cin>>n;
- generare(n);
- return 0;
- }
Add Comment
Please, Sign In to add comment