@gerrybio dp[i] should be thought of as sum of all prime factors (counted with multiplicity), then it's clear that it doesn't matter which prime you choose.

For example, dp[20] = 9 because 20 = 2x2x5 and 2+2+5 = 9. It doesn't matter if you calculate this sum as (2+2) + 5 (i.e. dp[4] + 20/4 ) or (2+5) + 2 (i.e. dp[10] + 20/10).