Probability of obtaining Prime Numbers as product of values obtained by throwing N dices | Function to find the value of power ( X , N ) ; Stores the value of ( X ^ N ) ; Calculate the value of power ( x , N ) ; If N is odd ; Update res ; Update x ; Update N ; Function to find the probability of obtaining a prime number as the product of N thrown dices ; Stores count of favorable outcomes ; Stores count of sample space ; Print the required probability ; Driver Code
function power ( x , N ) { let res = 1 ; while ( N > 0 ) { if ( N % 2 == 1 ) { res = ( res * x ) ; } x = ( x * x ) ; N = N >> 1 ; } return res ; } function probablityPrimeprod ( N ) { let N_E = 3 * N ; let N_S = power ( 6 , N ) ; document . write ( N_E + " " + N_S ) ; } let N = 2 ; probablityPrimeprod ( N ) ;