A geometric sequence $(a_n)$ has $a_1=\sin x$, $a_2=\cos x$, and $a_3= \tan x$ for some real number $x$. Find the value of $n$ such that $a_n=1+\cos x$.

Let's think step by step and output the final answer within \boxed{}.
user