Compute $\int_{0}^{1}\left[\frac{2}{x}\right]-2\left[\frac{1}{x}\right]dx$ The question is to find
$$\int_{0}^{1}\left(\left[\dfrac{2}{x}\right]-2\left[\dfrac{1}{x}\right]\right)dx,$$
where $[x]$ is the largest integer no greater than $x$, such as $[2.1]=2, \;[2.7]=2,\; [-0.1]=-1.$
Is there any nice method to solve this integral,Thank you everyone.

Some of my thoughts: I have if $a\in(0,1]$, then
$$\int_{0}^{1}\left[\dfrac{a}{x}\right]-a\left[\dfrac{1}{x}\right]dx=a\ln{a}.$$
What about $a>1$,
$$\int_{0}^{1}\left[\dfrac{a}{x}\right]-a\left[\dfrac{1}{x}\right]dx=?$$
and  $$\int_{0}^{1}\left(\left[\dfrac{2}{x}\right]-2\left[\dfrac{1}{x}\right]\right)^{2}dx=?$$
becasue I have
$$\int_{0}^{1}\left(\dfrac{1}{x}-\left[\dfrac{1}{x}\right]\right)^2=-1-\gamma+\ln{(2\pi)}$$
 A: You just have to figure out where the integrand is nonzero.  In this case, the integrand really takes the value
$$\left\lfloor \frac{2}{x} \right\rfloor - 2\left \lfloor \frac{1}{x} \right\rfloor = \begin{cases} \\0 & x \in \left [ \frac{2}{2 n+1},\frac{2}{2 n}\right )\\ 1 & x \in \left [ \frac{2}{2 n},\frac{2}{2 n-1}\right ) \end{cases}$$
for $n \ge 1$ and $x \in [0,1]$.  Here is a plot generated in Mathematica:

Thus, the integral is just a sum of the interval lengths over which the integrand has the value of $1$:
$$\begin{align}\int_0^1 dx \, \left ( \left\lfloor \frac{2}{x} \right\rfloor - 2\left \lfloor \frac{1}{x} \right\rfloor \right ) &= \frac{2}{3} - \frac{2}{4} + \frac{2}{5} - \frac{2}{6} + \ldots \\ &= 2 \left [ \sum_{k=1}^{\infty} \frac{(-1)^{k+1}}{k} - \frac12 \right ]\\ &= 2 \log{2} - 1\end{align}$$
A: We have
$$\left\lfloor \dfrac1x \right\rfloor = n \text{ if }x \in \left(\dfrac1{n+1}, \dfrac1n\right]$$
$$\left\lfloor \dfrac2x \right\rfloor = \begin{cases}2n+1 & \text{ if }x \in \left(\dfrac1{n+1}, \dfrac1{n+1/2}\right] \\ 2n & \text{ if }x \in \left(\dfrac1{n+1/2}, \dfrac1{n}\right] \end{cases}$$
We hence have
$$\left\lfloor \dfrac2x \right\rfloor - 2 \left\lfloor \dfrac1x \right\rfloor = \begin{cases} 1 & \text{ if }\left(\dfrac1{n+1}, \dfrac1{n+1/2}\right] \\ 0 & \text{ if }x \in \left(\dfrac1{n+1/2}, \dfrac1{n}\right] \end{cases}$$
Hence,
$$\int_0^1 \left( \left\lfloor \dfrac2x \right\rfloor - 2 \left\lfloor \dfrac1x \right\rfloor\right) dx = \sum_{n=1}^{\infty} \left(\dfrac1{n+1/2} - \dfrac1{n+1}\right) = 2\log2-1$$
One way to evaluate $$\sum_{n=1}^{\infty} \left(\dfrac1{n+1/2} - \dfrac1{n+1}\right)$$ is as follows. We have
$$f(x) = \sum_{n=1}^{\infty} \left(x^{n-1/2} - x^{n} \right) = \sum_{n=1}^{\infty} x^{n-1}\left(\sqrt{x} -x\right) = \dfrac{\sqrt{x}-x}{1-x} = \dfrac{\sqrt{x}}{1+\sqrt{x}}$$
Now we have
$$\int_0^1 f(x) dx = \sum_{n=1}^{\infty} \left(\int_0^1 x^{n-1} dx - \int_0^1 x^{n-1/2} dx\right) = \sum_{n=1}^{\infty} \left(\dfrac1n - \dfrac1{n+1/2}\right)$$
We also have
\begin{align}
\int_0^1 f(x) dx & = \int_0^1 \dfrac{\sqrt{x}dx}{1+\sqrt{x}} = \int_0^1 \dfrac{2t^2dt}{1+t} = 2\int_0^1 \dfrac{dt}{1+t} + 2\int_0^1 \dfrac{(t^2-1)dt}{1+t}\\
& = 2 \log(2) + 2 \int_0^1 (t-1) dt= 2\log(2)-1
\end{align}
A: Hint: If you start drawing this function, you will see that this integral can be expressed as a discrete (but infinite) sum of areas. So rather than evaluating an integral, you can evaluate a series instead. Finding that series is a big part of this problem.
A: Here is another solution using some advanced concept:
Let $I$ denote the integral in question. With the substitution $x \mapsto \frac{1}{x}$, we have
$$ I = \int_{1}^{\infty} \frac{[2x] - 2[x]}{x^2} \, dx. $$
Now performing the integration by parts,
\begin{align*}
I
&= \left[ - \frac{[2x] - 2[x]}{x} \right]_{1^{-}}^{\infty} + \int_{1^{-}}^{\infty} \frac{1}{x} d([2x] - 2[x]) \\
&= 1 + \lim_{n \to \infty} \int_{1^{-}}^{n^{+}} \frac{1}{x} d([2x] - 2[x]) \\
&= 1 + \lim_{n \to \infty} \left( \int_{1^{-}}^{n^{+}} \frac{1}{x} d[2x] - 2 \int_{1^{-}}^{n^{+}} \frac{1}{x} d[x] \right) \\
&= 1 + 2 \lim_{n \to \infty} \left( \int_{2^{-}}^{2n^{+}} \frac{1}{x} d[x] - \int_{1^{-}}^{n^{+}} \frac{1}{x} d[x] \right) \\
&= 1 + 2 \lim_{n \to \infty} \left( \sum_{k=2}^{2n} \frac{1}{k} - \sum_{k=1}^{n} \frac{1}{k} \right) \\
&= 1 + 2 \lim_{n \to \infty} \left(-1 + \sum_{k=1}^{n} \frac{1}{n+k} \right) \\
&= 2 \log 2 - 1.
\end{align*}
A: $\newcommand{\bbx}[1]{\,\bbox[15px,border:1px groove navy]{\displaystyle{#1}}\,}
 \newcommand{\braces}[1]{\left\lbrace\,{#1}\,\right\rbrace}
 \newcommand{\bracks}[1]{\left\lbrack\,{#1}\,\right\rbrack}
 \newcommand{\dd}{\mathrm{d}}
 \newcommand{\ds}[1]{\displaystyle{#1}}
 \newcommand{\expo}[1]{\,\mathrm{e}^{#1}\,}
 \newcommand{\ic}{\mathrm{i}}
 \newcommand{\mc}[1]{\mathcal{#1}}
 \newcommand{\mrm}[1]{\mathrm{#1}}
 \newcommand{\on}[1]{\operatorname{#1}}
 \newcommand{\pars}[1]{\left(\,{#1}\,\right)}
 \newcommand{\partiald}[3][]{\frac{\partial^{#1} #2}{\partial #3^{#1}}}
 \newcommand{\root}[2][]{\,\sqrt[#1]{\,{#2}\,}\,}
 \newcommand{\totald}[3][]{\frac{\mathrm{d}^{#1} #2}{\mathrm{d} #3^{#1}}}
 \newcommand{\verts}[1]{\left\vert\,{#1}\,\right\vert}$
\begin{align}
&\bbox[5px,#ffd]{\int_{0}^{1}\pars{%
\left\lfloor 2 \over x\right\rfloor -
2\left\lfloor 1 \over x\right\rfloor}\dd x}
\,\,\,\stackrel{x\ \mapsto\ 1/x}{=}\,\,\,
\int_{1}^{\infty}{%
\left\lfloor 2x\right\rfloor -
2\left\lfloor x\right\rfloor\, \over x^{2}}\,\dd x
\\[5mm] = &\
\lim_{N \to \infty}\pars{%
\int_{1}^{N}{\left\lfloor 2x\right\rfloor \over x^{2}}\,\dd x -
2\int_{1}^{N}{\left\lfloor x\right\rfloor \over x^{2}}\,\dd x}
\\[5mm] = &\
2\lim_{N \to \infty}\pars{%
\int_{2}^{2N}{\left\lfloor x\right\rfloor \over x^{2}}\,\dd x -
\int_{1}^{N}{\left\lfloor x\right\rfloor \over x^{2}}\,\dd x}
\\[5mm] = &\
2\lim_{N \to \infty}\pars{%
\int_{N + 1}^{2N}{\left\lfloor x\right\rfloor \over x^{2}}\,\dd x -
\int_{1}^{2}{\left\lfloor x\right\rfloor \over x^{2}}\,\dd x}
\\[5mm] = &\
-1 + 2\lim_{N \to \infty}\,\,\,
\sum_{k = N + 1}^{2N - 1}\,\,\,\int_{k}^{k + 1}{\left\lfloor x\right\rfloor \over x^{2}}\,\dd x =
-1 + 2\lim_{N \to \infty}\,\,\,
\sum_{k = N + 1}^{2N - 1}\,\,{1 \over k + 1}
\\[5mm] = &\
-1 + 2\lim_{N \to \infty}\,\,\,
\sum_{k = N + 2}^{2N}\,\,{1 \over k} =
-1 + 2\lim_{N \to \infty}\,\,\,
\pars{H_{2N} - H_{N - 1}}
\\[5mm] = &\
\bbx{2\ln\pars{2} - 1} \approx 0.3863 \\ &
\end{align}
