The problem does not mention anything about impossible cases? Is it to be assumed that all the test cases are valid?
For eg. take n=3 and K=6. Is there even a solution for this case?