Sum of series (n/1) + (n/2) + (n/3) + (n/4) +…….+ (n/n)
Based on the following observation, you can derive a $O(\sqrt{n})$ time algorithm ( by computing the sum on the right-hand side naively in a $O(\sqrt{n})$-sized loop): (For $n=10^{12}$ this yields $n=10^{6}$ which is enough for say competitive programming sites which usually allow ~10^8 operations)

For any positive integer $n$, Let $k=\lfloor\sqrt{n}\rfloor$:
$$
\sum_{i=1}^n \left\lfloor\frac{n}{i}\right\rfloor = 2\sum_{i=1}^k  \left\lfloor\frac{n}{i}\right\rfloor - k^2
$$


This post on Math StackExchange provides a clear visual proof of the equality above.
The following is a proof for the equality above that does not depend on a graph.
All variables below stand for positive integers. Let us fix $n$ and $k=\lfloor\sqrt{n}\rfloor$. For all $i, j\le n$, let
$\delta(i,j)=1$ if $i\cdot j\le n$. $\delta(i,j)=0$ otherwise. In particular,

$\delta(i,j) = 1$ if $i,j\le k$.
$\delta(i,j) = 0$ if $i,j\ge k+1$.

Proposition. $\left\lfloor\dfrac{n}{i}\right\rfloor = \displaystyle\sum_{j=1}^n \delta(i,j) $ for all $i$.
Proof. Both sides count the number of positive multiples of $i$ that are smaller than or equal to $n$. $\ \checkmark$
$$\begin{aligned}
\sum_{i=1}^n \left\lfloor\frac{n}{i}\right\rfloor 
&amp;= \sum_{i=1}^k \left\lfloor\frac{n}{i}\right\rfloor 
 + \sum_{i=k+1}^n \left\lfloor\frac{n}{i}\right\rfloor \\
&amp;= \sum_{i=1}^k \left\lfloor\frac{n}{i}\right\rfloor 
 + \sum_{i=k+1}^n \sum_{j=1}^n \delta(i,j)\\
&amp;= \sum_{i=1}^k \left\lfloor\frac{n}{i}\right\rfloor 
 + \sum_{i=k+1}^n \sum_{j=1}^k \delta(i,j)\\
&amp;= \sum_{i=1}^k \left\lfloor\frac{n}{i}\right\rfloor 
 + \sum_{j=1}^k \sum_{i=k+1}^n \delta(i,j)\\
&amp;= \sum_{i=1}^k \left\lfloor\frac{n}{i}\right\rfloor 
 + \sum_{j=1}^k\left(\sum_{i=1}^n \delta(i,j)-\sum_{i=1}^k \delta(i,j)\right)\\
&amp;= 2\sum_{i=1}^k \left\lfloor\frac{n}{i}\right\rfloor 
 - \sum_{j=1}^k\sum_{i=1}^k \delta(i,j))\\
&amp;= 2\sum_{i=1}^k \left\lfloor\frac{n}{i}\right\rfloor 
 - k^2 \quad \checkmark \\
\end{aligned}$$
The proof above is, basically, a direct translation of the visual proof.