We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Note the pattern repeats for every eight numbers. If N is a multiple of 8, player 2 can always choose some number to immediately cancel out player 1's move and move the total modulo 17 back to 0. For example, if player 1 chooses +2^1, player 2 can choose +2^5 and immediately nullify the previous move. The moves all come in cancelling pairs if and only if N results in only full "cycles", e.g. N is a multiple of 8.
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Powers Game
You are viewing a single comment's thread. Return to all comments →
python3, passes all test cases
an easy way to see why this works is to write out the first few moduli:
Note the pattern repeats for every eight numbers. If N is a multiple of 8, player 2 can always choose some number to immediately cancel out player 1's move and move the total modulo 17 back to 0. For example, if player 1 chooses +2^1, player 2 can choose +2^5 and immediately nullify the previous move. The moves all come in cancelling pairs if and only if N results in only full "cycles", e.g. N is a multiple of 8.