Ninja has recently learned to calculate the LCM of arrays and his teacher challenged him to solve a problem that no student was able to solve till now in the first attempt.
He gives two integers ‘N’ and ‘M’ and you need to find ‘N’ integers ‘A1’, ‘A2’, … , ‘AN’ such that :
A1 + A2 + … + AN = M
LCM ( A1, A2 , … , AN ) <= M/2
Here LCM is the least common multiple of numbers ‘A1’, ‘A2’, … , ‘AN’.
Output ‘N’ integers for which above conditions are satisfied. It is guaranteed that for given constraints, the answer always exists.
Example :N = 4
M = 6
Explanation :
One of the possible answers can be [ 1, 2, 2, 1].
Sum of elements = 1+2+2+1 = 6.
LCM of elements = LCM ( 1, 2, 2, 1 ) = 2 which is <= (6/2).
The first line contains an integer 'T' which denotes the number of test cases to be run. Then the test cases follow.
The only line of each test case contains two integers ‘N’ and ‘M’.
Output format :
For each test case, print ‘N’ integers satisfying the mentioned conditions.
Print the output of each test case in a new line.
Note :
You don’t need to print anything. It has already been taken care of. Just implement the given function.
1 <= T <= 10
3 <= M <= 10^9
3 <= N <= M
Time Limit : 1 sec
2
5 9
3 3
1 3 3 1 1
1 1 1
For test case 1 we have,
One of the possible answers can be [ 1, 3, 3, 1, 1].
Sum of elements = 1+3+3+1+1 = 9.
LCM of elements = LCM ( 1, 3, 3, 1, 1 ) = 3 which is <= (9/2).
For test case 2 we have,
One of the possible answers can be [ 1, 1, 1].
Sum of elements = 1+1+1 = 3.
LCM of elements = LCM ( 1, 1, 1 ) = 1 which is <= (3/2).
2
4 4
4 6
1 1 1 1
1 2 2 1
Try solving the problem for ‘N = 3’ first.
Approach :
Algorithm :
O(N), where N is the number of integers that satisfy the given condition.
We are printing the ‘N’ integers that satisfy the conditions, so the overall time complexity is O(N).
O(1)
Constant extra space is required. Hence, the overall Space Complexity is O(1).