Because hierarchy of logical operators says that in a statement, first all the logical NOT(!) should be processed, then logical AND(&&), and then logical OR(||).
So according to the first thing, condition 2 AND condition 3 should work. After that, if condition 1 OR the other two condition work, it will process the statements under it. This problem can be resolved by putting a bracket before condition 1, and after condition 2.
So it breaks down to - >
You have to represent N using K distinct odd digits
now if K is odd then N should be odd and if N is even K should be even.
You can check so by (N-K)%2 == 0. Then the minimum Number you can represent using K distinct odd digits is 1 + 3 + 5 + 7 + . … 2 * K + 1, by applying the Arithmetic Progression Formula you obtain that that series is equal to K^2, so now if N < K ^ 2 you can’t represent it where as if N >= K^2 you can always represent it let’s say N > K ^ 2 , so you can just change the last digit 2 * K + 1 by N - K^2 making it 2 * K + 1 + N - K^2, it will remain odd because N and K have the same parity so we will be doing odd + even. Hope this clears any doubts you had.