ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1023. Buttons

explain the logic behind this problem
Posted by Unsocial_A 20 Sep 2018 23:44
I have seen many people solve this problem using divisor of given number(k).But i cannot understand how it works.Can anyone explain me how this logic works??

sorry for bad english
Re: explain the logic behind this problem
Posted by PO 18 Jan 2019 12:58
you need to be in control. you are in control when you keep the first player in "loop". if you take number of buttons is 6, say, then the "loop" length is 3, i.e. if you take max number of buttons as 3 - 1 = 2, then whatever amount the first player takes you can keep them in loop. if they take first time 1, you take 2 - in sum 3, 3 - remaining, you are a winner. if they take 2 - you take 1, 3 remaining again - you are a winner.
so, idea is to find the smallest divisor of a number > 2 & answer will be that - 1. hope that makes sense.

Edited by author 18.01.2019 19:50