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.
If the two kangaroos met, then there woulde be an integer n such that =>x1 + n * v1 = x2 + n * v2 =>n * v1 = x2 - x1 + n * v2 =>n * v1 - n * v2 = x2 - x1 =>n * (v1 - v2) = (x2 - x1) =>n=(x2 - x1) / (v1 - v2) If this is an integer, then (x2 - x1) % (v1 - v2) has to equal 0.
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Number Line Jumps
You are viewing a single comment's thread. Return to all comments →
If the two kangaroos met, then there woulde be an integer n such that =>x1 + n * v1 = x2 + n * v2 =>n * v1 = x2 - x1 + n * v2 =>n * v1 - n * v2 = x2 - x1 =>n * (v1 - v2) = (x2 - x1) =>n=(x2 - x1) / (v1 - v2) If this is an integer, then (x2 - x1) % (v1 - v2) has to equal 0.