Skip to content

Commit 4630434

Browse files
author
Sahil
authored
Merge pull request royalpranjal#26 from khannagautam/khannagautam-patch-1
Added solution for Smallest sequence with given Primes
2 parents 108d83b + 3b55176 commit 4630434

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
vector<int> Solution::solve(int A, int B, int C, int D)
2+
{
3+
set<int> s;
4+
swap(A,D);
5+
int ctr = 0;
6+
vector<int> ans;
7+
s.insert(B);
8+
s.insert(C);
9+
s.insert(D);
10+
while(ctr<A)
11+
{
12+
auto i = s.begin();
13+
ans.push_back(*i);
14+
15+
s.insert((*i)*B);
16+
s.insert((*i)*C);
17+
s.insert((*i)*D);
18+
s.erase(i);
19+
ctr++;
20+
}
21+
return ans;
22+
}

0 commit comments

Comments
 (0)