Product of divisors of a number from a given list of its prime factors | C ++ Program to implement the above approach ; Function to calculate ( a ^ b ) % m ; Function to calculate and return the product of divisors ; Stores the frequencies of prime divisors ; Iterate over the prime divisors ; Update the product ; Update the count of divisors ; Driver Code
#include <bits/stdc++.h> NEW_LINE using namespace std ; int MOD = 1000000007 ; int power ( int a , int b , int m ) { a %= m ; int res = 1 ; while ( b > 0 ) { if ( b & 1 ) res = ( ( res % m ) * ( a % m ) ) % m ; a = ( ( a % m ) * ( a % m ) ) % m ; b >>= 1 ; } return res % m ; } int productOfDivisors ( int p [ ] , int n ) { map < int , int > prime ; for ( int i = 0 ; i < n ; i ++ ) { prime [ p [ i ] ] ++ ; } int product = 1 , d = 1 ; for ( auto itr : prime ) { int val = power ( itr . first , ( itr . second ) * ( itr . second + 1 ) / 2 , MOD ) ; product = ( power ( product , itr . second + 1 , MOD ) * power ( val , d , MOD ) ) % MOD ; d = ( d * ( itr . second + 1 ) ) % ( MOD - 1 ) ; } return product ; } int main ( ) { int arr [ ] = { 11 , 11 } ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; cout << productOfDivisors ( arr , n ) ; }