Find sum of divisors of all the divisors of a natural number | Returns sum of divisors of all the divisors of n ; Calculating powers of prime factors and storing them in a map mp [ ] . ; If n is a prime number ; For each prime factor , calculating ( p ^ ( a + 1 ) - 1 ) / ( p - 1 ) and adding it to answer . ; Driver code
function sumDivisorsOfDivisors ( n ) { let mp = new Map ( ) ; for ( let j = 2 ; j <= Math . sqrt ( n ) ; j ++ ) { let count = 0 ; while ( n % j == 0 ) { n = Math . floor ( n / j ) ; count ++ ; } if ( count != 0 ) mp . set ( j , count ) ; } if ( n != 1 ) mp . set ( n , 1 ) ; let ans = 1 ; for ( let [ key , value ] of mp . entries ( ) ) { let pw = 1 ; let sum = 0 ; for ( let i = value + 1 ; i >= 1 ; i -- ) { sum += ( i * pw ) ; pw = key ; } ans *= sum ; } return ans ; } let n = 10 ; document . write ( sumDivisorsOfDivisors ( n ) ) ;