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 . ; Driven Program
code: #include <bits/stdc++.h> NEW_LINE using namespace std ; int sumDivisorsOfDivisors ( int n ) { map < int , int > mp ; for ( int j = 2 ; j <= sqrt ( n ) ; j ++ ) { int count = 0 ; while ( n % j == 0 ) { n /= j ; count ++ ; } if ( count ) mp [ j ] = count ; } if ( n != 1 ) mp [ n ] = 1 ; int ans = 1 ; for ( auto it : mp ) { int pw = 1 ; int sum = 0 ; for ( int i = it . second + 1 ; i >= 1 ; i -- ) { sum += ( i * pw ) ; pw *= it . first ; } ans *= sum ; } return ans ; } int main ( ) { int n = 10 ; cout << sumDivisorsOfDivisors ( n ) ; return 0 ; }