What is the probability that the integer closest to the the random variable $N=\frac{X}{Y}$ is $0$? I have the following question:

Let $X,Y\sim Uni(0,1)$ be two random variables that are  independent. What is the probability that the integer closest to the the random variable $N=\frac{X}{Y}$ is $0$?

The solution they gave:
$$
P\left(0<N<0.5\right)=P\left(X<0.5Y\right)=\int_{0}^{1}\int_{0}^{0.5Y}1dxdy=\int_{0}^{1}0.5y=0.25
$$
I understand that we want to find the probably $P\left(0<N<0.5\right)$, but I don't understand how they moved from $P\left(X<0.5Y\right)$ to $\int_{0}^{1}\int_{0}^{0.5Y}1dxdy$. How did they think about it?
 A: In general, if $X$ and $Y$ are independent with densities $f_X$ and $f_Y$, and $Z=\frac XY$, then $Z$ has density
$$
f_Z(z)=\int_{\mathbb R}|y|f_X(zy)f_Y(y)\ \mathsf dy.\tag1
$$
This can be shown as follows: for $z\in\mathbb R$ we have
\begin{align}
F_Z(z) :&= \mathbb P(Z\leqslant z)\\
&= \mathbb P(X/Y\leqslant z)\\
&= \mathbb P(X\geqslant zY, Y<0) + \mathbb P(X\leqslant zY, Y>0)\\
&= \int_{-\infty}^0 \int_{zy}^\infty f_X(x)f_Y(y)\ \mathsf dx\ \mathsf dy + \int_0^\infty \int_{-\infty}^{zy} f_X(x)f_Y(y)\ \mathsf dx\ \mathsf dy.
\end{align}
Differentiating yields
$$
f_Z(z) = \frac{\mathsf d}{\mathsf dz}F_Z(z) = \int_{-\infty}^0-y f_X(yz)f_Y(y)\ \mathsf dy + \int_0^\infty y f_X(yz)f_Y(y)\ \mathsf dy = \int_{\mathbb R}|y|f_X(zy)f_Y(y)\ \mathsf dy.
$$
Here $f_X(x) = \mathsf 1_{(0,1)}(x)$ and $f_Y(y) = \mathsf 1_{(0,1)}(y)$, so we compute the density of $N$ as given by $(1)$:
\begin{align}
f_N(z) &= \int_{\mathbb R} y\cdot  \mathsf 1_{(0,1)}(zy)\mathsf 1_{(0,1)}(y)\ \mathsf dy\\
&= \left(\int_0^1 y\ \mathsf dy\right)\mathsf 1_{(0,1)}(z) + \left(\int_0^{1/z} y \ \mathsf dy\right)\mathsf 1_{(1,\infty)}(z)\\
&= \frac 12\cdot  \mathsf 1_{(0,1)}(z) + \frac1{2z^2}\mathsf 1_{(1,\infty)}(z).
\end{align}
Let $\tau=\arg\min_{k\in\mathbb N\cup\{0\}}\{|N-k|\}$. Then for each $k\in\mathbb N\cup\{0\}$, we have
\begin{align}
\mathbb P(\tau = k) &= \int_{(k-1/2\wedge 0)}^{k+1/2} f_N(z)\ \mathsf dz\\
&= \left(\int_0^{1/2}\frac 12\ \mathsf dz\right)\mathsf 1_{\{k=0\}} + \left(\int_{1/2}^1 \frac12\ \mathsf dz + \int_1^{3/2} \frac1{2z^2}\ \mathsf dz\right)\mathsf 1_{\{k=1\}} + \left(\int_{k-1/2}^{k+1/2} \frac1{2z^2}\ \mathsf dz\right)\mathsf 1_{\{k>1\}}\\
&= \frac14\mathsf 1_{\{k=0\}} + \frac5{12}\mathsf 1_{\{k=1\}} + \frac{2}{4 k^2-1}\mathsf 1_{\{k>1\}}.
\end{align}
So in particular, $\mathbb P(\tau=0)=\frac14$, as was to be shown.
A: Suppose $Y$ takes on a value on $(0,1)$. If $X$ takes on a value greater than $.5Y$, then $N = \frac{X}{Y}$ will be closest to an integer greater than or equal to $1$. Since $Y$ can selected arbitrarily on $(0,1)$, we are integrating $Y$ over the whole interval and for each selected value of $Y$ we are allowing values of $X$ to be between $0$ and $.5Y$. In $\int_{0}^{1}\int_{0}^{0.5Y}1dxdy$ the outer integral is choosing a value of $Y$ and the inner integral is choosing a value of $X$ given the constraint that $X$ must be on $(0, .5Y)$.
