text: Find sum of divisors of all the divisors of a natural number | C # program to 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
code: using System ; using System . Collections . Generic ; class GFG { public static int sumDivisorsOfDivisors ( int n ) { Dictionary < int , int > mp = new Dictionary < int , int > ( ) ; for ( int j = 2 ; j <= Math . Sqrt ( n ) ; j ++ ) { int count = 0 ; while ( n % j == 0 ) { n /= j ; count ++ ; } if ( count != 0 ) mp . Add ( j , count ) ; } if ( n != 1 ) mp . Add ( n , 1 ) ; int ans = 1 ; foreach ( KeyValuePair < int , int > entry in mp ) { int pw = 1 ; int sum = 0 ; for ( int i = entry . Value + 1 ; i >= 1 ; i -- ) { sum += ( i * pw ) ; pw = entry . Key ; } ans *= sum ; } return ans ; } public static void Main ( String [ ] args ) { int n = 10 ; Console . WriteLine ( sumDivisorsOfDivisors ( n ) ) ; } }