Count of ways to generate a Matrix with product of each row and column as 1 or | Java implementation of the above approach ; Function to return the number of possible ways ; Check if product can be - 1 ; Driver code
import java . util . Arrays ; class GFG { static void Solve ( int N , int M ) { int temp = ( N - 1 ) * ( M - 1 ) ; int ans = ( int ) ( Math . pow ( 2 , temp ) ) ; if ( ( N + M ) % 2 != 0 ) System . out . print ( ans ) ; else System . out . print ( 2 * ans ) ; } public static void main ( String [ ] args ) { int N = 3 ; int M = 3 ; Solve ( N , M ) ; } }