Product of proper divisors of a number for Q queries | C ++ implementation of the above approach ; Function to precompute the product of proper divisors of a number at it 's corresponding index ; Returning the pre - computed values ; Driver code
#include <bits/stdc++.h> NEW_LINE #define ll  long long int NEW_LINE #define mod  1000000007 NEW_LINE using namespace std ; vector < ll > ans ( 100002 , 1 ) ; void preCompute ( ) { for ( int i = 2 ; i <= 100000 / 2 ; i ++ ) { for ( int j = 2 * i ; j <= 100000 ; j += i ) { ans [ j ] = ( ans [ j ] * i ) % mod ; } } } int productOfProperDivi ( int num ) { return ans [ num ] ; } int main ( ) { preCompute ( ) ; int queries = 5 ; int a [ queries ] = { 4 , 6 , 8 , 16 , 36 } ; for ( int i = 0 ; i < queries ; i ++ ) { cout << productOfProperDivi ( a [ i ] ) << " , ▁ " ; } return 0 ; }