List of integers is formed such that all integers that can be written in form 2x3y5z are sorted in increasing order. So, list look like this: 1, 2, 3, 4, 5, 6, 8, 9, ... What is n-th element (0-indexed) in list?
0 < = n < = 105
Input
500
Output
944784
Am I missing anything, or answer for 500 is 937500?
It is 0-indexed. for n=0 answer is 1, for n=1 answer is 2... Maybe this?
Yep, you are right. There is simple O(n) algorithm:
Idea is same with fofao_funk's.
Yeah, I got it. Thank you
Disregarding the overflow, I think this should work: create an ordered set which contains the element 1 initially. Now, you will do the following n + 1 times: pop out the smallest element X in the set (and delete it) and then put the elements 2X, 3X and 5X in the set. The n + 1-th popped element is the answer.
Shouldn't that be MLE? I don't have ML but there is high probability for that, am I right?
You should use O(N) memory, since for each popped element (at most N) you put 3 other in the set.
Stupid me... Thank you