Probability of an even number I have been having problems solving the following problem.
Two real numbers $x$ and $y$ are chosen uniformly at random in the interval $(0,1)$. What is the probability that the closest integer to $x/y$ is even? 
I wrote a computer program to estimate the answer but I can't see how to solve it without one.
 A: The integer closest to $\frac xy$ is $n>1$ if $n-\frac12<\frac xy<n+\frac12$ or equivalently $(2n-1)y<2x<(2n+1)y$ (it doesn't really matter what you decide for the boundary cases or if you take $\le$ instead of $<$).
This describes a triangle with vertices $(0,0)$, $(\frac2{2n-1},1)$ and $(\frac2{2n+1},1)$ and that has area $A_n=\frac12(\frac{2}{2n-1}-\frac2{2n+1})=\frac2{4n^2-1}$.
In the special case $n=0$, we obtain a triangle with vertices $(0,0)$, $(1,0)$, and $(1,\frac12)$ and area $A_0=\frac14$.
The sought probability equals
$$ p =\sum_{k=0}^\infty A_{2k}\approx 0.4646.$$
This sum is also essentially the imaginary part of $\sum_{n=1}^\infty \frac{i^n}n$. More precisely (with the $\frac54$ coming from special treatment for $A_0$ and $\frac in$),
$$ p = \frac54-\Im\left(\sum_{n=1}^\infty \frac{i^n}n\right)=\frac54-\Im(\ln i)=\frac{5-\pi}4.$$
A: You can evaluate $\mathbb{P}(x/y < 1/2)$ and $\mathbb{P}(x/y \in ]k-1/2, k+1/2[)$ for every $k \geqslant 1$ :
$$\mathbb{P}(x/y < 1/2) = \mathbb{P}(x < y/2) = \int_{0}^1 \mathbb{P}(x < y'/2) dy' = \int_{0}^{1} (y'/2) dy' = 1/4$$
And
$$\mathbb{P}(x/y \in ]k-1/2, k+1/2[) \\= \mathbb{P}(x \in ](k-1/2)y, (k+1/2)y[) \\= \int_{0}^1 \mathbb{P}(x \in ](k-1/2)y', (k+1/2)y'[) dy' \\= \int_{0}^{\frac{1}{k+1/2}} \mathbb{P}(x \in ](k-1/2)y', (k+1/2)y'[) dy' + \int_{\frac{1}{k+1/2}} ^1 \mathbb{P}(x \in ](k-1/2)y', (k+1/2)y'[) dy' \\= \int_{0}^{\frac{1}{k+1/2}} y' dy' + \int_{\frac{1}{k+1/2}} ^1 1-(k-1/2)y' dy' \\= 1/(2k+1) + 1 - \frac{1}{k+1/2} - (k-1/2)(1/2 - (\frac{1}{k+1/2})^2)
\\= ~~...$$
A: You need to think for which numbers $x$ and $y$ the quotioned $x/y$ is even. 
In the end you can calculate something like this:
Prob $\Big[\cup_n [y(4n-1)/2 < x < y(4n+1)/2] \cup [0 < x < y/2] \Big]$ 
for $n=1,2,\dots$
Hope this helps!
