spoj#NSQUARE2. NSquare Sum ( Medium )
NSquare Sum ( Medium )
N-square Sum! Problem? ( Medium )
Given Q pairs of integers Ni, Ai ( 1 <= Ai, Q <= 10^5 , 4 <= N <= 10^2 ) a, find Ni numbers whose square sums is equal to Ai. If there're more than one solution, print the one lexicographically smallest . If there's no solution, print "Impossible".
Q = 1 Ni = 4 A1 = 16 { 4² + 0² + 0² + 0² = 16} |
Input
There's an integer Q ( 1 <= Q <= 10^5 ) in the first line; it stands for the number of queries. The next Q lines describe each query with two integers Ni, Ai ( 1 <= Ai <= 10^5, 4 <= Ni <= 10^2 ). Ni is the number of integers that you need to find whose sum of squares is equal to Ai.
Output
You have to print Q lines, each one with Ni numbers such that the sum of squares is equal to Ai. If there's no solution, you've to print "Impossible".
Example
Input: 1 4 16 Output: 0 0 0 4 Input: 1 4 15 Output: 1 1 2 3 |