Traversing through all prime factors .
res = 1 ; NEW_LINE for i in range ( 2 , int ( math . sqrt ( n ) ) + 1 ) : NEW_LINE INDENT count = 0 ; NEW_LINE curr_sum = 1 ; NEW_LINE curr_term = 1 ; NEW_LINE while ( n % i == 0 ) : NEW_LINE INDENT count += 1 ; NEW_LINE n //= i ; NEW_LINE curr_term *= i ; NEW_LINE curr_sum += curr_term ; NEW_LINE DEDENT res *= curr_sum ; NEW_LINE DEDENT