Introduction
This section will discuss the problem “Designing Competition”. First, let’s see the problem statement.
Problem statement-
Ninja has to participate in a designing competition. In this competition, he will be given a sheet of paper of length ‘l’ and breadth ‘b’. He has to cover this entire area of sheet with square colourful papers of equal dimensions. Each colourful square paper is of unit length and breadth, so we need exactly ‘l * b’ square papers to cover the entire sheet. Each square paper is diagonally split and colored in two colours - red and black as shown below:

There is only one rule of the competition that the participant should place colourful papers such that two adjacent square papers must not share the same colour on the edge. As shown below, design 1 is acceptable but design 2 is not acceptable as the last two squares share edges with the same colour.


There can be multiple design patterns that can be generated by placing these colourful square papers on the given sheet of dimension ‘l x b’ as each square can be rotated and placed in four ways. Ninja has yet not figured out which design he will submit for the competition and is wondering exactly how many total number of designs are possible. You have to help him to find out the total number of designs that are possible for a given pair of values of ‘l’ and ‘b’.
You will be given the dimension of sheet i.e. length and breadth of the sheet and you have to print the total number of designs possible for the given dimension. As this number may be large, print the total number of designs modulo 109 + 7.
Now that we understand the problem let's discuss the approach to solve it in the next section.
Also see, Euclid GCD Algorithm
Brute Force Approach
This section will discuss the brute force approach to solve the problem described in the previous section. We have to find the total number of designs possible. Imagine the sheet as coordinates. We can observe that if we fix the square paper of coordinates (i-1,j) and (i, j-1), then there will be only one possible orientation for coordinate (i,j) that will satisfy the rule of the competition. So, if we arrange the square papers in the first row and first column then the rest of the orientation will be uniquely determined.
There can be following four ways of placing square paper at (1, 1):

Now, each of the remaining squares of the first row and first column has two possible orientations that will satisfy the rule of the competition.
So, the total number of designs possible for a sheet of dimension ‘l x b’ is 2(l + b).
Algorithm
Step 1. First, the main function. Inside the main function, create variables ‘l’ and ‘b’ to store the given length and breadth of the sheet respectively, then call the function “numberOfDesigns()” to find the total number of designs possible.
Step 2. Next, create the function “numberOfDesigns()” to find the total number of designs possible for a given dimension of sheet. It takes the following input parameters:
- l: Length of the given sheet in the designing competition
-
arr: Breadth of the given sheet in the designing competition
Step 3. Inside the function “numberOfDesignsBinaryExp()”, first initialise a variable ‘ans’ and calculate 2(l + b) using a ‘for loop’
Step 4. Finally, print the calculated total number of designs possible for the given dimension of sheet.




