Print the Sequence
Medium Accuracy: 48.8% Submissions: 168 Points: 4

Construct the sequence arr[1], arr[2], ... by the following rules. For i=1 we put arr[1]=1. Now let i >= 2. Then arr[i] is the least positive integer such that the following two conditions hold
(i) arr[i] > arr[i - 1];
(ii) for all k, j < i we have arr[i] is not equal to n1 * arr[k] - n2 * arr[j].
Find the first n terms of this sequence.


Example 1:

n1 = 2, n2 = 1, n = 10
1 2 4 5 10 11 13 14 28 29 
The first 10 terms of the sequence is printed.

Example 2:

n1 = 1, n2 = 1, n = 5
1 2 3 4 5
The first 5 terms of the sequence is printed.


Your Task:
You don't need to read input or print anything. Your task is to complete the function findSeq() which takes 3 Integers n1, n2, and n as input and returns a vector denoting the first n terms of the sequence.


Expected Time Complexity: O(n2)
Expected Auxiliary Space: O(n2)


1<= n1,n2 <= 50

1 <= n <= 103

We are replacing the old Disqus forum with the new Discussions section given below.
Click here to view old Disqus comments.

to report an issue on this page.


We strongly recommend solving this problem on your own before viewing its editorial. Do you still want to view the editorial?


All Submissions

My Submissions:

Login to access your submissions.

Print the Sequence

Output Window