sourabh_jangid's blog

By sourabh_jangid, history, 4 years ago, In English

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.

  • Vote: I like it
  • +13
  • Vote: I do not like it

»
4 years ago, # |
Rev. 4   Vote: I like it +15 Vote: I do not like it

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 years ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    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 years ago, # |
Rev. 2   Vote: I like it +27 Vote: I do not like it

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

  • »
    »
    4 years ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

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

  • »
    »
    4 years ago, # ^ |
      Vote: I like it +3 Vote: I do not like it

    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 years ago, # ^ |
        Vote: I like it +7 Vote: I do not like it

      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?