Find the $n$th number that is not a multiple of $3,5$ or $15$

61 Views Asked by At

Ok, so the problem I am solving is to find the $n$th number that is not a multiple of $3,5$ or $15$, where $n$ is an integer. I am given only $n$ to solve the problem.

For example, the $4$th number in this sequence would be $7$ since it is the fourth number that is not a multiple of the given numbers above.

$1,2,-,4,-,-,7,8,-,10$

An interesting pattern I noticed was that the $n$th number is always [$n\ +$ (#number of multiples before the number represented by $n$)]. For example, the $4$th number is $7$. If we find the number of multiples before $7$, which is $3$ and add that to $4$, we get the number we are looking for: $7$.

So, I have set up a simple equation to solve for this. $x$ notates the number we are looking for (also an integer) $$ x=n\ + \ \lfloor(\frac{x}{3} + \frac{x}{5} - \frac{x}{15})\rfloor $$ The expression in the floor function is to find the number of multiples present before the number $x$. The simplified form of the equation is: $$ x\ -\ \lfloor\frac{7x}{15}\rfloor = n $$ From here, I thought of brute forcing my way into finding $x$ by plugging in values of $x$ and seeing whether it is equal to $n$, but that would seem troublesome for large numbers $n>10^8$, even on a computer. Even if two $x$ values give the same value of $n$, the correct answer would be $\min(x_1,x_2).$ So, is there any way to simplify this further or perhaps, another way to solve this problem? I am still a novice and today is my first day actually interacting with floor and ceiling functions, lol. Thank you, any help is appreciated.