I want to calculate
$$\sum_{i=1}^n \gcd(i,n)$$
(Pillai function) for large n ($\ 1 \leq n \leq 10^{15}\ $). There is one formula involving Euler's totient formula but that requires calculating values of Euler's totient function for all divisors of $\ n\ $. What is the best method to do so?
Even in python.
This script
prints
essentially instantaneously.