Find nth number that does not belong to a set of numbers.

73 Views Asked by At

So, this problem is a competitive programming problem, but I find it to be quite mathematical. Basically, we have to find the nth number that does not lie in a set of number. The set of numbers given are: {1, 2, 4, 6} + all numbers of the form 10+4*k (k >= 0). So the set is: {1, 2, 4, 6, 10,14, 18...}. I feel the answer will be done using binary search but I am not sure how to go about solving this problem.

1

There are 1 best solutions below

0
On BEST ANSWER

We have

$$\left\{\left\lfloor\frac43n\right\rfloor-1\right\}=\{0,1,\;3,4,5,\;7,8,9,\;11,12,13,\;15,16,17,\;\ldots\}$$

If you toss out a few numbers at/near the beginning of this sequence, you have the complement of the given sequence. I'll leave the details of adjusting this to you.