For your not-working solution, one of the case I found that doesn't make sense is when your input is 10. In this case, if you step through your program, you will find your output is 1, but the correct output should be 2. This is also why you don't pass the secret test case for group 1, which is meant for testing when there is no remaining block left.