Product of proper divisors of a number for Q queries | Python3 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
mod = 1000000007 NEW_LINE ans = [ 1 ] * ( 100002 ) NEW_LINE def preCompute ( ) : NEW_LINE INDENT for i in range ( 2 , 100000 // 2 + 1 ) : NEW_LINE INDENT for j in range ( 2 * i , 100001 , i ) : NEW_LINE INDENT ans [ j ] = ( ans [ j ] * i ) % mod NEW_LINE DEDENT DEDENT DEDENT def productOfProperDivi ( num ) : NEW_LINE INDENT return ans [ num ] NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT preCompute ( ) NEW_LINE queries = 5 NEW_LINE a = [ 4 , 6 , 8 , 16 , 36 ] NEW_LINE for i in range ( queries ) : NEW_LINE INDENT print ( productOfProperDivi ( a [ i ] ) , end = " , ▁ " ) NEW_LINE DEDENT DEDENT