Sum of all divisors from 1 to n | Utility function to find sum of all divisor of number up to ' n ' ; Driver code
< ? php function divisorSum ( $ n ) { $ sum = 0 ; for ( $ i = 1 ; $ i <= $ n ; ++ $ i ) $ sum += floor ( $ n / $ i ) * $ i ; return $ sum ; } $ n = 4 ; echo divisorSum ( $ n ) , " STRNEWLINE " ; $ n = 5 ; echo divisorSum ( $ n ) , " STRNEWLINE " ; ? >