Блог пользователя sourabh_jangid

Автор sourabh_jangid, история, 4 года назад, По-английски

You are given three numbers as input $$$A$$$, $$$B$$$, $$$K$$$.
Perform the given below steps K times:-
if $$$A$$$ <= $$$B$$$ then
$$$B$$$ = $$$B$$$ $$$-$$$ $$$A$$$
$$$A$$$ = $$$A$$$ $$$+$$$ $$$A$$$
else
$$$A$$$ = $$$A$$$ $$$-$$$ $$$B$$$
$$$B$$$ = $$$B$$$ $$$+$$$ $$$B$$$

After K steps output the values of $$$A$$$ and $$$B$$$.
$$$0$$$ $$$\leq$$$ $$$A$$$, $$$B$$$ $$$\leq$$$ $$$10 ^ {9}$$$
$$$1$$$ $$$\leq$$$ $$$K$$$ $$$\leq$$$ $$$10 ^ {10}$$$.
If someone can give some hints it will be helpful.

  • Проголосовать: нравится
  • +13
  • Проголосовать: не нравится

»
4 года назад, # |
Rev. 4   Проголосовать: нравится +15 Проголосовать: не нравится

Sorry, that ( my first edit ) is incorrect, because the values of $$$A$$$ and $$$B$$$ keep changing after each operation.

The only observation that comes to my mind is, the sum of $$$A$$$ and $$$B$$$ will always be constant. Maybe that can be used somehow.

  • »
    »
    4 года назад, # ^ |
      Проголосовать: нравится 0 Проголосовать: не нравится

    At first, I thought that maybe the values will repeat after some operations so I need to find the cycle, but for large $$$A$$$, $$$B$$$ it doesn't repeat quickly.

»
4 года назад, # |
Rev. 2   Проголосовать: нравится +27 Проголосовать: не нравится

Let $$$A+B=S$$$. $$$S$$$ is constant and $$$A$$$ is transformed to $$$2A \% S$$$ on every step (in both cases).

  • »
    »
    4 года назад, # ^ |
      Проголосовать: нравится 0 Проголосовать: не нравится

    Wow, I was just thinking about this but didn't realize it happened when $$$ A = A - B $$$ too.

  • »
    »
    4 года назад, # ^ |
      Проголосовать: нравится +3 Проголосовать: не нравится

    Thanks man, so in the end $$$A$$$ is $$$(2 ^ {K} * A)$$$ $$$mod$$$ $$$S$$$.
    And also according to you what would be the rating of this problem if it has appeared in a codeforces contest.

    • »
      »
      »
      4 года назад, # ^ |
        Проголосовать: нравится +7 Проголосовать: не нравится

      I don't really have a feeling of the numerical ratings below 2400. Probably it would be a Div1B but maybe it also could be A?