SUM and REPLACE
HardRating 2000CodeforcesSegment Tree & Fenwick Tree
Approach hintTry it first, then revealHide
Replacing x by its number of divisors shrinks it to 1 or 2 within about six steps. Keep the range maximum next to the sum and skip any node whose maximum is at most 2; precompute divisor counts with a sieve.