Skip to content
TheChatArchiveThe Chat Archive
DeepSeekDeepseek v3.2· deepseekHugging Face Frontier Reasoning Traces

You are given two positive integers n (1 ≤ n ≤ 10^9) and k (1 ≤ k ≤ 100). Represent the…

  1. User

    You are given two positive integers n (1 ≤ n ≤ 10^9) and k (1 ≤ k ≤ 100). Represent the number n as the sum of k positive integers of the same parity (have the same remainder when divided by 2).

    In other words, find a_1, a_2, …, a_k such that all a_i>0, n = a_1 + a_2 + … + a_k and either all a_i are even or all a_i are odd at the same time.

    If such a representation does not exist, then report it. Input

    The first line contains an integer t (1 ≤ t ≤ 1000) — the number of test cases in the input. Next, t test cases are given, one per line.

    Each test case is two positive integers n (1 ≤ n ≤ 10^9) and k (1 ≤ k ≤ 100).

    Output

    For each test case print:

    • YES and the required values a_i, if the answer exists (if there are several answers, print any of them);
    • NO if the answer does not exist.

    The letters in the words YES and NO can be printed in any case.

    Example

    Input

    8 10 3 100 4 8 7 97 2 8 8 3 10 5 3 1000000000 9

    Output

    YES 4 2 4 YES 55 5 5 35 NO NO YES 1 1 1 1 1 1 1 1 NO YES 3 1 1 YES 111111110 111111110 111111110 111111110 111111110 111111110 111111110 111111110 111111120

  2. DeepSeek Assistant

    We need to parse the problem. It says: Represent n as sum of k positive integers all of same parity (all even or all odd). If exists, output YES and the numbers; else NO.

    Given constraints: t up to 1000, n up to 1e9, k up to 100.

    We need to output any valid representation.

    We need to think: For given n and k, can we find k positive integers (all even or all odd) summing to n? And produce them.

    Observations: All numbers are either all even or all odd. Their sum parity:

    • If all are even: sum is even (since sum of even numbers is even).
    • If all are odd: sum parity: sum of k odd numbers is odd if k is odd, even if k is even. Because each odd contributes 1 mod 2, so total mod 2 = k mod 2.

    Thus n must have parity consistent with parity of sum.

    Case all even: n must be even. Also each a_i = 2 * b_i, with b_i positive integers. Then sum = 2 * sum(b_i) = n => sum(b_i) = n/2. So we need to represent n/2 as sum of k positive integers (b_i > 0). That's always possible if n/2 >= k? Actually we need positive integers; b_i >= 1, so sum(b_i) >= k. So condition: n/2 >= k. Also n even. So for all even solution: n even and n >= 2k.

    Case all odd: each a_i is odd: a_i = 2b_i - 1? Actually odd positive integer can be represented as 2b_i - 1 where b_i >=1 integer; then a_i = 2b_i - 1, sum = 2*sum(b_i) - k = n => sum(b_i) = (n + k)/2. Since b_i >= 1, sum(b_i) >= k, so (n+k)/2 >= k => n+k >= 2k => n >= k. Also parity: n must have parity same as k mod 2? Because sum of k odd numbers mod2 = k mod2. So we need n mod 2 = k mod 2. Additionally, all a_i are positive odd, so minimal sum is k (all ones). So we need n >= k and parity match.

    But also b_i must be positive integers, sum(b_i) = (n+k)/2. Since b_i are any positive integers, we can always represent any integer S >= k as sum of k positive integers (by taking k-1 ones and the remainder as the last). So condition: (n+k)/2 >= k => n >= k. And parity condition: n ≡ k (mod 2). That's sufficient for all odd case.

    But careful: In the all odd case, if we set a_i = 1 for i=1..k-1 and a_k = n - (k-1) (since sum of first k-1 ones is k-1, then last must be n - (k-1)). But that last number might be even? It must be odd. Since n and k have same parity, n - (k-1) has parity: n - (k-1) mod2 = n - (k-1) = (n mod2) - ((k-1) mod2). Since n ≡ k (mod2), k-1 ≡ k-1 (mod2). If k is odd, k-1 even => n odd - even = odd? Actually let's compute: if k odd, then n odd, k-1 even => n - (k-1) odd. If k even, n even, k-1 odd => even - odd = odd. So indeed n - (k-1) is odd. Also it must be positive: n - (k-1) > 0 => n > k-1, which holds since n >= k. So the construction works: all ones except last is n - (k-1). However, we must ensure all a_i are odd. The ones are odd, and the last is odd. So that yields a valid all odd representation.

    Thus for all odd case: n >= k and n%2 == k%2.

    But we should also consider that maybe both conditions can be satisfied, then either representation works; we can output any.

    Now is there any other nuance? Possibly the all even case can also be represented by using even numbers that are not all same? Yes, but condition is simple: n even and n >= 2k. Then we can do similar: set first k-1 evens as 2 (i.e., a_i = 2) and last a_k = n - 2*(k-1). Check that last is even: n is even, subtract 2*(k-1) which is even, so even. And positive? n - 2*(k-1) >= ? need >0: n > 2(k-1) => n >= 2k-1? Actually for n even and n >= 2k, then n - 2(k-1) >= 2k - 2k + 2 = 2 >0. So ok. But what if n=2k-2? That is even but less than 2k? Actually 2k-2 is less than 2k, but condition we require n >= 2k to have all positive even numbers? Let's check minimal sum of k positive evens: smallest even positive integer is 2, so minimal sum = 2k. So indeed we need n >= 2k. So condition n even and n >= 2k is necessary and sufficient. So for all even solution: n even and n >= 2k.

    But note: There is also possibility of all odd numbers when n is even? Only if k is even because sum of even number of odd numbers is even. So condition covers both.

    Thus overall, solution exists if either:

    • n >= k and n%2 == k%2 (odd parity case)
    • n even and n >= 2k (even parity case)

    Because if n odd, only odd case can work (since sum of even numbers is even). For n odd, condition requires k odd and n >= k. So if n odd and k even, impossible. But maybe we could use a mix? But all numbers must be same parity, so no mix. So those are the only possibilities.

    But wait: Could there be a case where n is even, n >= 2k but also n >= k and n%2 == k%2 (i.e., k even)? Then both work; we can output any.

    Now check sample:

    Input: 8 10 3 -> n even, n=10, k=3. Check odd: n%2=0, k%2=1 -> parity mismatch, so odd impossible. Check even: n>=2k? 2k=6, 10>=6, yes. So even possible. Output: YES; numbers: 4 2 4? That's sum 10, all even? 4,2,4 are all even. So ok. But note they didn't use minimal 2's; they gave 4,2,4. So any representation.

    Second: 100 4 -> n even, k=4 even. Check odd: n%2=0, k%2=0 -> parity match, n>=4 (yes). So odd works. They output: 55 5 5 35 -> all odd? 55 odd,5 odd,5 odd,35 odd. Sum=100. So they used odd representation. Even also possible but they chose odd.

    Third: 8 7 -> n=8 even, k=7 odd. Odd: parity mismatch (8 even, 7 odd) -> no. Even: n>=2k? 2k=14, 8<14 -> no. So NO. Output matches.

    Fourth: 97 2 -> n odd, k=2 even. Odd: parity mismatch (97 odd, 2 even) -> no. Even: n even? n odd so no. So NO.

    Fifth: 8 8 -> n even, k=8 even. Odd: parity match, n>=8, so possible. They output all ones? Actually they output: 1 1 1 1 1 1 1 1 sum=8 all odd? Wait 1 is odd. Yes all ones, sum=8. That matches odd case.

    Sixth: 3 10 -> n=3, k=10. n even? no. odd? parity: n%2=1, k%2=0 mismatch, so odd fails. Even requires n even fails. So NO.

    Seventh: 5 3 -> n=5 odd, k=3 odd. odd case: n>=3 and parity match => yes. They output: 3 1 1 -> all odd, sum=5. Yes.

    Eighth: 1000000000 9 -> n even, k=9 odd. odd: parity mismatch. even: n>=2k? 2k=18, 1e9>=18 yes. So even case. They output 8 numbers of 111111110 and last 111111120? Actually they output: 111111110 (eight times?) Let's see: "111111110 111111110 111111110 111111110 111111110 111111110 111111110 111111110 111111120" That's 9 numbers: eight 111111110 and one 111111120. Sum? 8*111111110 = 888888880, plus 111111120 = 1,000,000,000. All are even? 111111110 even? last digit 0 -> even. 111111120 even. So yes.

    Thus conditions correct.

    Now we must implement: For each test case, check conditions and output.

    Edge Cases:

    • k=1: Then we need a single positive integer = n, with either even or odd. So if we want all same parity, we just need that n itself is either even or odd. But condition: odd case requires n%2 == 1%2? Actually k=1 odd, so odd case requires n odd and n>=1 => always true for odd n. Even case requires n even and n>=2? Actually minimal even positive integer is 2, so n must be even and n>=2? But n is positive integer; if n is 2, okay; if n is 0? Not allowed (n>=1). But n can be 2,4,... but what about n=1? n=1 is odd, so only odd case works. n=2 even, both even and odd? For odd: n=2 even, k=1 odd, parity mismatch, so odd fails. Even case: n even and n>=2 => yes. So works. So condition both: if n odd -> odd case works; if n even -> even case works? Actually for k=1, even case condition is n even and n>=2, but n could be 2? Yes. But what about n=0 not considered. So for n=2, even works. So always possible? For k=1, any n>=1 works because we can take [n] itself and check parity? But [n] is trivially of same parity (since only one number). So always YES. Let's see if our conditions yield that: Odd case: n>=k (n>=1) and n%2==k%2? For k=1, k%2=1, so need n odd. So if n odd, ok. Even case: n even and n>=2k=2 => n even and n>=2. If n is even but n=2, works; if n even but n=0 not considered. So if n is even and >=2, works. But what about n even = 2? works. What about n even = 4? works. So all n >=1 are covered: odd n -> odd case; even n -> even case because even case requires n even and n>=2. For n even, n>=2 automatically because smallest even positive integer is 2. So yes, all n works. So for k=1 always YES.

    But careful: if n=0? Not in range. So ok.

    • k large up to 100, n maybe small. Conditions will properly reject.

    Now implement: For each test case: Read n,k. If (n >= k and (n%2) == (k%2)): Then we can output odd representation. Use construction: a_i = 1 for i=1..k-1, a_k = n - (k-1). Note that n - (k-1) must be odd positive; we verified condition ensures it's odd and >0. Output YES and the numbers. Else if (n % 2 == 0 and n >= 2k): Then even representation: a_i = 2 for i=1..k-1, a_k = n - 2(k-1). Must be even positive; condition ensures it's >=2. Output YES and numbers. Else: Output NO.

    But need to ensure that in odd representation when k=1, the construction with k-1 =0 would give a list of 0 numbers? Actually we must handle separately: if k==1, just output [n] (which will satisfy parity automatically). Our generic construction works if we treat k-1 =0: we would have no "1"s? In code, we can do: produce list of length k-1 filled with 1, then append remainder. If k=1, then the list of first k-1 is empty, remainder = n - 0 = n. So it's fine. However, need to ensure that remainder is odd? For k=1, condition for odd case is n odd. But if we use odd representation when condition satisfied (n odd), then remainder = n is odd, ok. For k=1 even case? We'll use even case if n even. That's fine.

    But note: In the odd case, we must ensure all numbers are odd. With our construction, if k>1, the remainder n-(k-1) is odd as argued. For k=1, it's n which is odd by condition. So all good.

    Similarly for even case: remainder n-2*(k-1) is even (since n even and subtract even). For k=1, remainder n, which is even by condition.

    Now, there is a nuance: For odd case, minimal sum is k (all ones). So condition n>=k is necessary. However, what about n exactly equals k? Then all ones works. Our construction: a_i =1 for i=1..k-1, and a_k = n - (k-1) = k - (k-1) =1. So all ones. Works.

    For even case, minimal sum is 2k. So n=2k works: all twos. Our construction: k-1 twos => sum=2(k-1), remainder = n - 2(k-1)=2k - 2(k-1)=2. So all twos.

    Thus algorithm is straightforward.

    But wait: There is also possibility that both conditions hold and we may output either. The problem says print any.

    Edge Cases: n and k up to 1e9 and 100 respectively. Summing to compute numbers is safe in 64-bit (use long long). n up to 1e9, k up to 100, so n - (k-1) up to 1e9, fine.

    Now, is there any scenario where odd case condition holds but the constructed numbers may violate positivity? n - (k-1) must be >= 1. Since n >= k, n - (k-1) >= 1, ok. For even case, n - 2(k-1) must be >= 2? Actually we need positive even, at least 2. If n >= 2k, then n - 2(k-1) >= 2k - 2k + 2 = 2, so ok.

    But what about n = 2k - 1? That is odd? If n odd and k? 2k-1 is odd; parity with k: if k is odd, 2k-1 odd => parity match? For k odd, 2k-1 odd, so n%2 =1, k%2=1, match, n>=k? Since 2k-1 >= k for k>=1? For k=1, 1>=1; for k>1, 2k-1 > k. So odd condition would be satisfied? But then n = 2k-1, minimal sum of k odd numbers is k (all ones). So it's possible. For example, n=3,k=2? 3 is odd, k=2 even -> parity mismatch, so not possible. For k odd, say k=3, n=5 (23-1=5) works as sample. For k=5, n=9? 25-1=9, works? Sum of five odd numbers minimal 5; 9 can be 1,1,1,1,5 (odd) etc. So indeed possible. So odd case not constrained by n>=2k.

    Thus algorithm is correct.

    However, let's double-check for even case: what if n is even but less than 2k, e.g., n=4, k=3. Then minimal even sum is 6 >4, impossible. Our condition will reject. Good.

    Now, one nuance: Could there be representation using all odd numbers when n is even and k is even? We used condition n%2==k%2 which for even k and even n is true. But also n must be >= k. For n even but small, say n=2, k=2. Then n>=k yes, parity even=even, so odd case condition holds. But is it possible? Need two odd positive integers sum to 2. Minimal odd positive integer is 1, so we could have 1+1=2. Indeed both odd. So we would output 1,1. That is valid. So our condition holds. So we should check odd case first? Order doesn't matter, but we need to output YES if either is true. In the sample for 100 4 they output odd representation, though even also possible. So it's fine.

    But careful: In some test cases, the odd representation may produce a number that is even? Let's verify for n even and k even: Our construction yields a_k = n - (k-1). Since n even, subtract (k-1) which is odd (because k even => k-1 odd). Even - odd = odd. So remainder is odd. So all numbers are odd. Good.

    Thus algorithm is correct.

    Now about formatting: For each test case, we need to output "YES" on one line, then the k numbers on next line? According to sample: For each test case, they output YES, then on next line the numbers separated by space. If NO, just output NO on a line. And they do not print blank lines between test cases. So we'll follow that.

    Thus code: Loop t times, read n,k. Use long long for n, but n up to 1e9 fits int. Use long long for intermediate to be safe.

    Pseudo:

    for each test case: if (n >= k && (n % 2 == k % 2)): // odd representation vector ans(k, 1); ans[k-1] = n - (k-1); // but careful: we set first k-1 to 1, last to remainder. Actually easier: ans = [1]* (k-1) + [n - (k-1)]. // But if k=1, then we have only last. // ensure remainder positive odd. print "YES" print ans separated by space else if (n % 2 == 0 && n >= 2k): // even representation vector ans(k, 2); ans[k-1] = n - 2(k-1); print "YES" print ans else: print "NO"

    But careful: In even representation, we used ans initialized to 2 for all? Actually we set first k-1 to 2, and last to remainder. Equivalent: ans = vector of size k, fill with 2, then ans[k-1] = n - 2*(k-1) (if we index from 0, last index). However note that if k=1, ans = [2] initially, but then remainder = n - 0 = n, which should be n (even). But if we fill with 2 and then set last to n, it's fine. But we must ensure that for k=1, we don't erroneously include extra 2's? Actually if we fill the whole vector with 2, then set last to n, that will be correct: only one element, first we set it to 2, then replace with n. So it's fine.

    But we could also construct without temporary vector: Just output k-1 times "2 " then the remainder. That's efficient.

    Similarly for odd: output k-1 times "1 " then remainder.

    But note: The remainder must be printed as integer. If remainder is large, it's fine.

    Now one more nuance: In odd representation, when k is very large (up to 100) and n is huge (1e9), the remainder will be n - (k-1) which is about 1e9, and the ones are small. All positive.

    One potential issue: For odd representation, what if remainder becomes 1? That's fine; all numbers are 1.

    Now test: n=100, k=4, odd representation: three 1's and remainder 97? Actually n-(k-1)=100-3=97. So numbers: 1 1 1 97. That sum is 100, all odd. That's also valid. But sample output used 55 5 5 35. So any works.

    Now, is there any scenario where both conditions hold but one construction may produce a number that is not positive? For odd construction, remainder = n - (k-1) is at least n - (k-1). Since n >= k, it's at least 1. So positive. For even construction, remainder >=2. So okay.

    But is there any scenario where odd condition holds but n - (k-1) is even? Should not because parity ensures odd. Good.

    Now verify with edge cases:

    Case: n=2, k=2. n even, k even => odd condition: n>=k (2>=2) and parity match (even=even) => true. So odd representation: 1 and 1 (since k-1=1 => one 1, remainder = 2-1=1). Actually we would output: 1 1. That's valid. Even representation also possible (2 0? Actually minimal even sum is 2+2=4 >2, so even condition fails because n>=2k? 2>=4 false). So only odd works. So output 1,1.

    But is 1 odd? yes. So valid.

    Case: n=4, k=2. n even, k even => odd condition: 4>=2 and parity match => true, odd representation: 1 and 3 (both odd) sum 4. That's valid. Even condition: n>=2k? 4>=4 true, so both. So either.

    Case: n=6, k=3. n even, k odd => odd condition fails (parity mismatch), even condition: 6>=6? yes, even representation: two 2's and remainder 6-4=2 -> 2,2,2 all even sum 6. That's valid. Odd condition fails.

    Case: n=6, k=4. n even, k even => odd condition works: three 1's and remainder 6-3=3 -> 1,1,1,3 sum 6 all odd. Also even condition: 6>=8 false, so only odd works.

    Thus correct.

    Now, potential trap: Could there be a representation with all numbers odd when n is even and k is even, but n < k? No, because minimal sum of k odd numbers is k (all ones) which is even if k even? Actually sum of k odd numbers when k even is even. Minimal sum is k (since ones sum to k). For k even, k is even. So if n is even and less than k, then n < k, but minimal sum is k > n, so impossible. So condition n>=k is necessary. So our condition covers that.

    Now, could there be a representation with all even numbers when n is odd? No, sum even.

    Thus algorithm is complete.

    But let's double-check with some random cases. We'll code.

    Implementation details:

    We have up to 1000 test cases. For each, we need to print numbers. We can build a string or directly print.

    Pseudo-code in C++:

    #include #include using namespace std; int main() { int t; cin >> t; while (t--) { long long n, k; cin >> n >> k; if (n >= k && (n % 2) == (k % 2)) { // odd cout << "YES\n"; for (int i = 0; i < k-1; i++) cout << "1 "; cout << n - (k-1) << "\n"; } else if (n % 2 == 0 && n >= 2k) { // even cout << "YES\n"; for (int i = 0; i < k-1; i++) cout << "2 "; cout << n - 2(k-1) << "\n"; } else { cout << "NO\n"; } } return 0; }

    But need to ensure we use long long for n and calculations because n up to 1e9 fits in int, but multiplication 2*(k-1) with k up to 100 is fine in int. But to avoid warnings, use long long.

    Now test with sample. Should match.

    But note: Sample output for 1000000000 9: they used 8 numbers of 111111110 and one 111111120. That's a different construction. Our even construction would give 8 twos? Actually even construction: k=9 -> print 8 times "2 " and remainder = 1000000000 - 16 = 999999984. That would be: 2 2 2 2 2 2 2 2 999999984. All even. But 999999984 is even. That would be valid. But they used another representation; any is fine.

    But wait: is 999999984 even? Yes, ends with 4. So it's fine. However, is there any chance that 999999984 is less than 2? No, it's huge. So that's fine. So we can output that. But the sample output uses numbers that are more balanced. We can output our simpler representation.

    Thus answer accepted.

    But before finalizing, consider if there is any tricky case where our construction might produce a number that is not positive? For odd case when n = k? remainder = n - (k-1) = 1, so ok. For n = k+1? remainder = 2? But n and k parity must match: if k is odd, n odd? k+1 is even if k odd. So parity mismatch, so odd case not allowed. If k even, n even? k+1 is odd, parity mismatch. So not relevant. So remainder always odd and >=1.

    But what about n = k with even numbers? Not possible because n must be >= 2k.

    So all good.

    Now, let's consider the possibility of using all odd numbers with a different construction that ensures all numbers are >0. Already satisfied.

    Now, double-check: Could there be a scenario where n is even, k is odd, but we could use all odd numbers? No because sum of odd number of odds is odd, can't be even. So that's impossible.

    Thus solution done.

    But wait: There's also a possibility of using all even numbers when n is odd? No.

    Thus final answer.

    But before finalizing, ensure that we handle the case when k=0? Not possible as k>=1.

    Now let's think about the time complexity: O(t * k). t <= 1000, k <= 100 => at most 100k numbers printed, which is fine.

    Now, just to be thorough, let's test some extreme values:

    1. n=1e9, k=100, n even? 1e9 is even? Actually 1,000,000,000 is even. k=100 even. Both conditions: odd case: n>=k and parity match => 1e9>=100 and even=even -> true. So odd representation: 99 ones and remainder = 1e9 - 99 = 999999901? Wait that's 1,000,000,000 - 99 = 999,999,901. Is that odd? 1e9 even, subtract 99 odd => odd. So numbers: 1 repeated 99 times, and 999,999,901. All odd? 999,999,901 is odd. But is that positive? Yes. So valid. That's simpler than using even representation? Even representation would use 99 twos and remainder = 1e9 - 198 = 999,999,802 which is even. Both work. So our algorithm may output odd representation because we check that first. That's fine.

    But note: The remainder 999,999,901 is less than 1e9, but that's fine.

    1. n=100, k=99. n even, k odd -> odd condition fails (parity mismatch). Even condition: n>=2k? 2k=198 >100, fails. So NO. Indeed, minimal sum of 99 positive even numbers is 198 >100, and sum of 99 odds (minimal 99) is 99, but sum of 99 odds parity is odd (99 mod2=1) but n even, so impossible. So NO.

    2. n=99, k=100. n odd, k even -> parity mismatch, even condition fails (n odd). So NO.

    3. n=101, k=99. n odd, k odd -> parity match, n>=99 -> odd representation: 98 ones and remainder=101-98=3. So numbers: 98 ones and 3, all odd. Good.

    All fine.

    Thus solution seems correct.

    But wait: The problem statement says "Represent the number n as the sum of k positive integers of the same parity (have the same remainder when divided by 2)." It doesn't say they must be all odd or all even? That's exactly the definition: same parity means all even or all odd. So our interpretation is correct.

    Now, one subtle nuance: In some combinatorial problems, sometimes they also consider the possibility of all numbers being zero? No, positive integers, so >0.

    Thus final.

    However, I want to double-check the conditions more rigorously.

    Let's derive necessary and sufficient conditions formally:

    We want existence of positive integers a_i all even => a_i = 2 b_i, b_i >= 1 => sum 2 b_i = n => sum b_i = n/2. For integer b_i positive, we need n even and n/2 >= k. So n >= 2k.

    Or all odd => a_i = 2 b_i - 1, b_i >= 1 => sum (2 b_i -1) = 2 sum b_i - k = n => sum b_i = (n+k)/2. We need (n+k) even (i.e., n and k same parity) and (n+k)/2 >= k => n >= k. And positivity: b_i >= 1 ensures a_i >=1 automatically (since a_i = 2 b_i -1 >= 1 if b_i >=1). So conditions: n >= k and n ≡ k (mod 2).

    Thus necessary and sufficient: (n >= 2k and n even) OR (n >= k and n%2 == k%2).

    But is there any overlapping region where both hold? Yes, but that's fine.

    Now, is there any scenario where n even and n>=2k but also n%2 == k%2? That would require k even (since n even). So for n even and k even, both conditions hold. But note: If n even and k even and n >= k, the odd condition also holds because parity matches and n>=k. So indeed both hold. But what if n even, k even, but n < 2k? Then odd condition holds (since n>=k? yes if n>=k but n<2k, e.g., n=4,k=2: both hold? n>=k and parity match, so odd condition holds; even condition fails). So that's consistent.

    Thus our if-else with odd first would handle both.

    One more nuance: What about n even, k even, but n = k? Example n=2,k=2? n=2 even, k=2 even: n>=k yes, parity match yes, so odd condition holds. Even condition requires n>=2k=4 false. So odd representation yields 1 and 1, sum 2. Works. Good.

    What about n=2,k=2: odd representation yields 1 and 1. That's fine.

    What about n=0? Not allowed.

    Thus perfect.

    Now, consider the edge where n=2k-2 and k even? Example n=6,k=4? n=6 even, k=4 even, n>=k (6>=4) and parity match => odd condition holds. So odd representation: three 1's and remainder = 6-3=3 -> 1,1,1,3. Works. Even condition fails because n < 8. So correct.

    Now, for n=2k-2 and k odd? n=4,k=3? n=4 even, k=3 odd -> odd condition fails (parity mismatch). Even condition: n>=2k? 4>=6 false. So NO. But can we represent 4 as sum of 3 positive even numbers? Minimum sum = 6, so impossible. Sum of 3 odds min = 3, but sum of 3 odds parity is odd, so cannot get 4 (even). So indeed NO. So correct.

    Thus final answer.

    But let's also think about the possibility that the representation might require all numbers to be strictly positive, not zero. Our constructions ensure positivity.

    Now, check for overflow: n - 2*(k-1) could be negative? But we only call it when n >= 2k, so n - 2(k-1) >= 2, fine.

    Thus code is ready.

    But we must also consider that in the odd representation, if k is 1, we print nothing for the loop and then remainder = n. That's fine.

    Now about the output formatting: In the sample, for YES they print YES on one line and then numbers on next line. For NO they just print NO. So we should follow that.

    Make sure to include newline after numbers.

    Now, I'll produce final solution.

    Wait: There's a subtle case: The problem constraints say k up to 100, but n up to 1e9. In the odd representation, we might have remainder = n - (k-1). For large k, e.g., k=100, remainder = n - 99. If n = 100? Then remainder = 1. That's fine. But if n is exactly k? Then remainder = 1. Also fine. If n is slightly above k, remainder small but positive.

    Thus all good.

    Now, I'm thinking: Could there be a case where the odd representation yields a remainder that is 0? That would require n = k-1, but then n < k, so condition fails. So not possible.

    Thus solution correct.

    Let's write final code.

    But before finalizing, I will test the code on sample manually:

    Input: 8 10 3 -> n>=k?10>=3, parity?10%2=0,3%2=1 mismatch => false. Even:10 even,10>=6 true => output YES, then 2 2 and remainder=10-4=6? Actually 2*(k-1)=4, remainder=6. So output: 2 2 6? Wait we output k-1=2 times "2 " then remainder 6. So "2 2 6". That's sum 10 all even. But sample output is "4 2 4". But any is acceptable. So code would output "2 2 6". That's fine.

    But could there be any reason that "2 2 6" is invalid? 6 is even, all positive, sum 10. Good.

    But in sample, they used "4 2 4". That's also valid. So any.

    Now 100 4: odd condition true (100>=4, parity even/even). So code outputs 1 1 1 and remainder=100-3=97: "1 1 1 97". Sample output "55 5 5 35". Both fine.

    8 7: odd fails, even fails => NO.

    97 2: odd fails, even fails => NO.

    8 8: odd true => output seven 1's and 1? Actually remainder=8-7=1, so eight 1's: "1 1 1 1 1 1 1 1". That's exactly sample.

    3 10: odd fails (3<10) (parity? 3 odd,10 even mismatch) even fails (3 odd) => NO.

    5 3: odd true => output two 1's and remainder=5-2=3 => "1 1 3". Sample is "3 1 1". Equivalent.

    1000000000 9: odd fails (parity mismatch), even true => output eight 2's and remainder=1000000000-16=999999984 => "2 2 2 2 2 2 2 2 999999984". That's fine.

    Thus output would differ but should be accepted.

    Now check if any test case could cause our constructed remainder to be 0 or negative due to miscalculation? Should not.

    So final code is ready.

    However, I recall there might be a nuance: For odd representation, we need to ensure that the remainder is odd, which we rely on parity condition. For even representation, need remainder even, which we rely on n even. But also we need remainder positive. For even representation when n = 2k exactly, remainder = 2k - 2(k-1) = 2, ok. For n = 2k+2? remainder = 2k+2 - 2(k-1) = 4, ok. So good.

    Now, consider the possibility that we might need to output numbers in any order. So our order (k-1 ones/twos then remainder) is fine.

    Potential improvements: The problem might have restrictions that numbers should be printed in non-decreasing order? Not required; any order.

    Thus final answer.

    Now, we can produce code.

    But there's also a potential catch: The problem statement says "If such a representation does not exist, then report it." And "The letters in the words YES and NO can be printed in any case." So we can output YES/NO in uppercase or lowercase.

    Now, one more nuance: In some Codeforces problems, they require that the numbers be printed on the same line after YES? In sample they print YES on one line and then numbers on next line. So we follow that.

    Now, verify for t=1000, printing is fine.

    Time to produce final solution.

    But wait, consider the case n=1, k=1: odd condition true (1>=1 and parity match (1%2=1, k%2=1)). So output YES and "1". That's fine.

    n=1, k=2: odd condition false (1<2). even condition false (1 odd). So NO. Indeed, sum of two positive integers both odd? Minimum 1+1=2 >1. Both even min 2+2=4 >1. So impossible.

    n=2, k=1: odd condition? 2>=1 but parity? k=1 odd, n even -> mismatch, so false. even condition: n even and n>=2? 2>=2 true, so output YES "2". Good.

    n=2, k=2: odd condition true (2>=2 and even/even) so output YES with 1 and 1.

    Thus all good.

    Now, think about possible integer overflow in (n - (k-1))? n up to 1e9, k up to 100 => subtraction is fine.

    Now, I will produce final answer in C++.

    Potential memory: No issues.

    Now, we need to output numbers separated by spaces, no trailing space? But if we loop and print space after each, then at the end we might have extra space. But typical judges ignore trailing whitespace. However, we can format nicely: for i in 0..k-2 print number and space, then last number without space, then newline.

    Simplify: Use stringstream? Could but not necessary.

    C++ code:

    #include<bits/stdc++.h> using namespace std;

    int main() { int t; cin >> t; while (t--) { long long n, k; cin >> n >> k; if (n >= k && (n % 2) == (k % 2)) { cout << "YES\n"; for (int i = 0; i < k - 1; ++i) cout << "1 "; cout << n - (k - 1) << "\n"; } else if (n % 2 == 0 && n >= 2 * k) { cout << "YES\n"; for (int i = 0; i < k - 1; ++i) cout << "2 "; cout << n - 2 * (k - 1) << "\n"; } else { cout << "NO\n"; } } return 0; }

    But check: In the even case, we need to ensure that n - 2*(k-1) is even and positive. It will be.

    But I realize: The condition (n % 2 == 0 && n >= 2 * k) might be insufficient if k is 1? For k=1, 2*k = 2, but n=2 works, n>=2 true, so output YES with for loop i<0, then remainder = n - 0 = n. So output "2". That's correct. For n=0? not allowed.

    Now, is there any case where both conditions could be true, but our first branch (odd) would be taken, which is fine. But note: For n even, k even, both hold. However, odd construction yields some ones and a large odd number. That's acceptable. However, some judges might have a preference that numbers should be "nice"? Not required.

    But one issue: The odd construction might produce a remainder that is 1? That's fine. But what if remainder becomes 0? Not possible.

    Thus final code.

    Now, I will produce final answer.

    But before finalizing, I want to double-check with the sample: For 10 3, our output would be "2 2 6". That's valid. But the sample output for that case is "4 2 4". However, the problem statement says "if there are several answers, print any of them". So it's fine.

    Thus answer.

    Now, perhaps we could also consider a more balanced representation for even case when n is large, but not necessary.

    Now, think about potential pitfalls: The output for YES must be on two lines: first line "YES", second line the numbers. Our code prints "YES\n" then the numbers and then newline. That yields two lines. For NO, it prints "NO\n". That matches.

    Edge: For k=0? Not possible.

    Thus final.

    One more nuance: The problem might be from Codeforces Round #... I recall there is a problem "Same Parity Summands" (CF 1352A?). Actually I recall a problem "Same Parity Summands" where they had similar constraints. There is also a variant where they require that the numbers be "positive integers" and you need to output k numbers of same parity. The solution described is exactly what we have.

    But I recall there is a twist: The even representation might also be constructed as (n - 2*(k-1)) must be even and positive. This is fine. However, I've seen solutions that check if n is odd and k is odd, then use odd case, else if n is even and k <= n/2 then use even case, etc. That's similar.

    But wait, there is also possibility that for odd case, we could also use all numbers as odd but not necessarily include many ones; but we did.

    Thus done.

    Now, will there be any hidden case where odd condition holds but the remainder (n - (k-1)) is not odd? Let's test with n even, k even: e.g., n=10, k=4 => remainder=10-3=7 odd. Good. n even, k even, remainder = even - odd = odd. n odd, k odd: n=9,k=3 => remainder=9-2=7 odd. So always odd.

    Thus good.

    Now, perhaps we should consider using long long for n and k because multiplication 2k can exceed int? k up to 100, 2k=200 fits int. But for safety, use long long.

    Now final code.

    But I realize: In the even case, we used "n >= 2k". However, if n is even and n >= 2k, then n - 2*(k-1) >= 2. So it's fine. But what about the scenario n = 2k - 2? That is even but less than 2k, so condition fails, which is correct because minimal sum of k even numbers is 2k. So indeed we must use n >= 2k, not n >= 2k - 2. So condition is correct.

    Now, note: There is another potential representation: Use a mix of both? No, must be same parity.

    Thus final answer.

    I'll write final solution accordingly.

    However, there is one more nuance: In some interpretations, the "same parity" might mean that all numbers have the same remainder when divided by 2, but also they could be all even or all odd. That's exactly our interpretation.

    Thus final solution.

    Now, think about memory and speed: t up to 1000, k up to 100, so printing up to 100 numbers per test, total 100k prints, trivial.

    Now, we need to provide answer in required format.

    Thus final answer.

    But before finalizing, double-check the sample with our code:

    Input: 8 10 3 YES 2 2 6 100 4 YES 1 1 1 97 8 7 NO 97 2 NO 8 8 YES 1 1 1 1 1 1 1 1 3 10 NO 5 3 YES 1 1 3 1000000000 9 YES 2 2 2 2 2 2 2 2 999999984

    That differs from sample but should be accepted.

    Now, I'll produce final answer.

    But to be thorough, let's consider an alternative: Some might argue that for odd case, we could also use numbers that are all odd but not necessarily using ones; but our construction is fine.

    Now, also consider the scenario where n is huge and k=100, and we output 99 ones and a huge odd number. That's fine.

    Now, consider the time: all good.

    Now, final answer in C++.

    But there is a catch: In the even case, if we output many 2's and a large remainder, but if n is just barely above 2k, the remainder will be small: e.g., n=2k+2: remainder = 2k+2 - 2(k-1) = 4. So we get (k-1) twos and a 4. That's fine.

    Now, ensure that the remainder is at least 2: For n=2k, remainder=2; for n=2k+2, remainder=4; for n=2k+4, remainder=6; etc. All even and positive.

    Thus okay.

    Now, final answer.

    But I'm thinking: Could there be a situation where both conditions fail but a representation exists with all odd numbers when n is odd and k is even? Let's check: sum of even number of odd numbers is even, cannot be odd. So no. With all even numbers, sum is even, cannot be odd. So indeed no.

    Thus necessary and sufficient.

    Now, I think it's solved.

    Let's also consider a scenario where n is even, k odd, but n is large enough to be expressed as sum of odd numbers? Sum of odd number of odd numbers is odd, can't be even. So no.

    Thus algorithm stands.

    Now, implement.

    One more nuance: The problem says "positive integers" which are >0. So our ones and twos are fine.

    Thus final solution.

    Now, I will produce final answer with code.

    But the problem originally maybe had a note: "If there are several answers, print any of them." So our answer is fine.

    Now, I'll write final answer.

    But before concluding, check a tricky case: n=100, k=3. n even, k odd => odd fails (parity mismatch), even condition: n>=6? yes, 100>=6. So even representation: 2 2 and remainder 96: 2,2,96. All even? 96 even. So valid. But could there also be an odd representation? No because parity mismatch. So fine.

    Now, test with n=2, k=3. n even, k odd => odd fails, even: n>=6? 2<6 fails. So NO. Indeed sum of three positive evens min 6 >2; sum of three odds min 3 (odd) but parity odd, cannot be 2 (even). So NO.

    Now, test with n=3, k=3: n odd, k odd => odd: n>=3 and parity match => YES: 1 1 1. So sum 3. Works.

    Now, test with n=3, k=5: n odd, k odd? 5 odd => parity match, but n>=5? 3<5 => false. So NO. Indeed min sum 5 >3.

    Thus correct.

    Now, test with n=1000000000, k=100 (both even). Odd condition true -> output 99 ones and remainder = 1000000000-99 = 999999901. That is odd? 999999901 mod 2 = 1. So all odd. That's valid. Even condition also true but we use odd. That's fine.

    Now, think about the size: 999999901 is within int? It's less than 1e9, fine.

    Now, we could also output even representation if we wanted to avoid huge numbers? Not required.

    Thus answer.

    Now, potential issue: The problem might expect that the numbers are output in a particular order, such as non-decreasing? Not specified. So any order works.

    Thus final answer.

    Now, produce final answer. ```cpp

    #include using namespace std;

    int main() { int t; cin >> t; while (t--) { long long n, k; cin >> n >> k;

        // all odd case
        if (n >= k && (n % 2) == (k % 2)) {
            cout << "YES\n";
            for (int i = 0; i < k - 1; ++i)
                cout << "1 ";
            cout << n - (k - 1) << "\n";
        }
        // all even case
        else if (n % 2 == 0 && n >= 2 * k) {
            cout << "YES\n";
            for (int i = 0; i < k - 1; ++i)
                cout << "2 ";
            cout << n - 2 * (k - 1) << "\n";
        }
        else {
            cout << "NO\n";
        }
    }
    return 0;
    

    }