Product of proper divisors of a number for Q queries | Java 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
import java . util . * ; class GFG { static final int mod = 1000000007 ; static long [ ] ans = new long [ 100002 ] ; static 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 ; } } } static long productOfProperDivi ( int num ) { return ans [ num ] ; } public static void main ( String [ ] args ) { Arrays . fill ( ans , 1 ) ; preCompute ( ) ; int queries = 5 ; int [ ] a = { 4 , 6 , 8 , 16 , 36 } ; for ( int i = 0 ; i < queries ; i ++ ) { System . out . print ( productOfProperDivi ( a [ i ] ) + " , ▁ " ) ; } } }