Sum of all divisors from 1 to n |  ; t1 = i * ( num / i - i + 1 ) adding i every time it appears with numbers greater than or equal to itself t2 = ( ( ( num / i ) * ( num / i + 1 ) ) / 2 ) - ( ( i * ( i + 1 ) ) / 2 ) adding numbers that appear with i and are greater than i ; Driver code
import math NEW_LINE def sum_all_divisors ( num ) : NEW_LINE INDENT sum = 0 ; NEW_LINE for i in range ( 1 , math . floor ( math . sqrt ( num ) ) + 1 ) : NEW_LINE INDENT sum += t1 + t2 ; NEW_LINE DEDENT return sum ; NEW_LINE DEDENT n = 1 NEW_LINE sum = sum_all_divisors ( n ) NEW_LINE print ( sum ) NEW_LINE