


The first line of input contains an integer ‘T’ denoting the number of test cases.
The first and only line of the test case consists of a single integer ‘N’.
Return the maximum possible product Ninja can obtain by breaking integer ‘N’ into ‘K’ parts.
You do not need to print anything, it has already been taken care of. Just implement the given function.
1 <= ‘T’ <= 11
2 <= ‘N’ <= 55
Time Limit: 1 sec
The main idea is to break the given integer ‘N’ into all possible ways and out of all possible ways the one with the maximum product will be the answer.
Algorithm:
In Approach 1 there are many overlapping sub-cases Hence we will apply memoization in Approach 1 to avoid calculating sub-problems many times.
In the above sub-tree, we are calculating 2 two times and 1 two times.So we will use memoization to avoid calculating same problems.
Algorithm:
The main idea is to use the observation when the given number is broken into 2 and 3’s will give a maximum answer. If n%3 == 0 it means that the given number is a multiple of 3 hence break it as the sum of 3’s so the answer for this case will be pow(3, N/3).When N%3 == 2 then it means the given number can be broken into a sum of 2 and N/3 3’s.So answer for this case will be 2 * pow(3, N/3).
When N%3 == 1 it means that the given number can be broken into the sum of 4 and N/3 - 1 3’s (N>=2) . 4 will give the maximum answer when broken into 2 2’s. Hence answer for this case will be 4* pow(3, N/3-1).
Algorithm: