Probability mass function of closest integer of ratio of uniform random variables Given two random numbers $X$ and $Y$ between 0 and 1 define $Z$ to be the closest integer to $X/Y$. I know what the ratio of two uniform random variables (that is I know its PDF and CDF). However, working with this has gotten me nowhere for finding the above PMF. I have drawn various pictures but I cannot seem to generalize the result for any $X$ and $Y$. Any help is much appreciated. This was given as an in-class exercise (to be done before the next period and then discussed in class) and I wanted to be prepared for the discussion during the next class period. I do believe there are a few different cases such as when $Y \geq 1/2$ and when $Y<1/2$. but I can never get a concise value for differing intervals.
 A: A trick is to reduce everything to domains included in $[0,1]\times[0,1]$. Then one can use repeatedly the fact that, for every $0\leqslant a\leqslant b\leqslant1$, the events $U(a,b)=[aX\leqslant Y\leqslant bX]$ and $V(a,b)=[aY\leqslant X\leqslant bY]$ have probability $E[(b-a)Y]=E[(b-a)X]=\frac12(b-a)$ (note the condition that $a$ and $b$ are both in $[0,1]$, otherwise the result fails). Thus:


*

*The event $[\color{green}{\mathbf{K=0}}]=[\frac{X}Y\lt\frac12]=[X\lt\frac12Y]=V(0,\frac12)$ has probability $\frac12(\frac12-0)=\color{red}{\mathbf{\frac14}}$. 

*For every $\color{green}{\mathbf{k\geqslant2}}$, the event $[\color{green}{\mathbf{K=k}}]=[k-\frac12\lt\frac{X}Y\lt k+\frac12]$ is $[a_kX\lt Y\lt b_kX]=U(a_k,b_k)$ with $a_k=\frac1{k+\frac12}$ and $b_k=\frac1{k-\frac12}$ hence it has probability $\frac12(b_k-a_k)=\color{red}{\mathbf{\frac2{4k^2-1}}}$.

*To compute the probability of $[\color{green}{\mathbf{K=1}}]$, either one sums the other probabilities and one completes the sum to $1$, or one notes that $[K=1]=[\frac12\lt\frac{X}Y\lt\frac32]$ is the disjoint union of the events $[\frac12Y\lt X\lt Y]=V(\frac12,1)$ and $[\frac23X\lt Y\lt X]=U(\frac23,1)$ hence the probability of the event $[K=1]$ is $\frac12(1-\frac12)+\frac12(1-\frac23)=\color{red}{\mathbf{\frac5{12}}}$.


Sanity check:
$$
\frac14+\frac5{12}+\sum_{k=2}^\infty\frac2{4k^2-1}=1.
$$
A: Hint: $P\left\{ K=k\right\} =P\left\{ \left(k-\frac{1}{2}\right)Y<X<\left(k+\frac{1}{2}\right)Y\right\} =\underset{S}{\int\int}dxdy$
for $S=\left\{ \left(x,y\right)\in\left(0,1\right)^{2}\mid\left(k-\frac{1}{2}\right)y<x<\left(k+\frac{1}{2}\right)y\right\} $
