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

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

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
  • Проголосовать: не нравится

»
6 лет назад, скрыть # |
← 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.

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

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