
a1 + a2 + a3 = N
LCM(a1, a2, a3) <= N/2
Let N = 4, then we can choose 1, 1, and 2. The sum of these integers is 4 which is equal to ‘N’ and their LCM is 2 which is <= N/2.
The first line will contain a single integer ‘T’ denoting the number of test cases. Then the test cases follow.
The first line of each test case will contain a single integer ‘N’, denoting the positive integer Ninja has.
For each test case, print three space-separated integers satisfying the required conditions.
You can print the integers in any order.
You are not required to print anything; it has already been taken care of. Just implement the function.
1 <= T <= 1000
3 <= N <= 10^9
Time Limit: 1 sec.
We will iterate over all the possible values for each integer and the combination of integers that satisfies the required conditions will be the answer.
Observe that if ‘N’ is odd, then the answer will be ‘N’/2, ‘N’/2, and 1. Because since ‘N’ is odd (‘N’/2 + ‘N’/2) will equal to (‘N’ - 1) and hence we can get an extra 1 to add which will be our third integer. And the LCM of them will also be ‘N’/2 which satisfies our condition.
Otherwise, if ‘N’ is divisible by 4, then the answer will be ‘N’/2, ‘N’/4, and ‘N’/4. Here (‘N’/2 + ‘N’/4 + ‘N’/4) will sum up to ‘N’ and their LCM will be ‘N’/2 since ‘N’/4 are factors of ‘N’/2.
Else, if ‘N’ is even by not divisible by 4, then the answer will be ‘N’/2 - 1, ‘N’/2 - 1, 2. Because here (‘N’/2 - 1 + ‘N’/2 - 1) will equal to (‘N’ - 2) and hence we got 2 as our third integer. Moreover, since ‘N’ is even but ‘N’ is not divisible by 4, ‘N’/2 will be odd and as a result (‘N’/2 - 1) will be even. Again 2 is a factor of every even number. So the LCM of these integers will be (‘N’/2 - 1) which is less than ‘N’/2.
Algorithm: