Project Euler Problem 642
Let f(n) be the largest prime factor of n and displaystyle F(n) = sum{i=2}^n f(i).
Solution
Answer: 631499044
A standard approach is to rewrite the sum by grouping integers according to their greatest prime factor.
Let $P(n)$ denote the largest prime factor of $n$. Then
$$F(N)=\sum_{n=2}^N P(n).$$
If $p=P(n)$, then $n=pm$ where every prime factor of $m$ is $\le p$. Thus the count of integers $n\le N$ with largest prime factor exactly $p$ equals the count of $p$-smooth numbers $\le N/p$.
Using the decomposition
$$F(N) = \sum_{p\le \sqrt N} p,\Psi!\left(\frac Np,p\right) + \sum_{k\le \sqrt N}!\Bigl(\sum_{p\le N/k}p\Bigr) - \lfloor\sqrt N\rfloor!\sum_{p\le \sqrt N}p,$$
where $\Psi(x,y)$ is the count of $y$-smooth numbers $\le x$, one can evaluate the result efficiently using a Lagarias–Miller–Odlyzko style prime-summatory routine together with a smooth-number counter.
Evaluating this for
$$N=201820182018$$
and reducing modulo $10^9$ gives:
Answer: 631499044