Help me in solving BREAKSTICK problem

My issue

When i want to work with 17 3,i can divide the stick in 3,3,3,3,3,2 which is not parity. Again in case of 19 5,i can divide the stick in 5,5,5,4. But in the most of the solutions they only checked if N is odd and X is even or not. But here we get “NO” for the odd odd case too. The code down below is the most liked code i picked. But can anyone explain the cases I asked?

My code

#include <bits/stdc++.h>
#define ll long long

using namespace std;

int main() {
	int t;
	cin>>t;
	
	while(t--){
	    ll n,x;
	    cin>>n>>x;
	    
	    string ans="YES";
	    
	    if(x%2==0 && (n%2)!=0)
    	    {
    	        ans="NO";
    	    }
	        
	   cout<<ans<<endl;
	}
	return 0;
}

Problem Link: Break the Stick Practice Coding Problem - CodeChef

The code you written is absolutely correct.
comming to your question you argue that odd-odd case is also “NO” but 17,3 can be written as 3,3,3,3,5 and 19,5 is 5,5,9 or 5,7,7 so they are “YES”
The above sum can be explained as
let x1,x2—xk be the lengths of k sticks coming from stick of length n
if x1,x2—xk are even then thier sum will be even.
if x1,x2—xk are odd then thier sum can be even or odd depending on value of k
I hope this explanation helps you

1 Like

thanks !