The problem can be found here: https://onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=4878

**I know the final answer but idk how to get it myself.**

The final answer will be the $$$summation(phi[i]) - 1$$$ for all $$$i$$$ from $$$1$$$ to $$$n$$$ where $$$phi[i]$$$ is the Euler's totient function.