Probability of obtaining Prime Numbers as product of values obtained by throwing N dices | C ++ program to implement the above approach ; 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
#include <bits/stdc++.h> NEW_LINE using namespace std ; long long int power ( long long int x , long long int N ) { long long int res = 1 ; while ( N > 0 ) { if ( N & 1 ) { res = ( res * x ) ; } x = ( x * x ) ; N = N >> 1 ; } return res ; } void probablityPrimeprod ( long long int N ) { long long int N_E = 3 * N ; long long int N_S = power ( 6 , N ) ; cout << N_E << " ▁ / ▁ " << N_S ; } int main ( ) { long long int N = 2 ; probablityPrimeprod ( N ) ; }