TCS CodeVita Season 9 Registration is going on Register soon — Click here
TCS CodeVita Previous Year Question must be completed before sitting in the actual round of coding.
Want to know more about TCS Codevita?We have covered a great part of the introduction to TCS CodeVita here you must read this: Click here to open.
The Great Chase
Problem :
Welcome to the Planet Zandar, the second most prominent planet in the Milky Way Galaxy (of course after our own Earth).
The planet is in a distress condition, a Group of Galactic pirates, Zorons have stolen the Trident Crystal, which is the main source of energy of the planet, and are escaping the Galaxy. The Nova Corps, the military agency of Zandar, have gathered intelligence that the Zoronion space craft can run in cosmic leaps of exactly D units, (it means that the space craft will move D units from its position in every leap/turn) and is currently I units away from Zandar.
The Zandarian Space crafts can run in cosmic leaps of exactly Z units. The Commander of Nova Corps wants to know the smallest number of leaps required to catch Zorons (Note that it is possible to catch the pirates only when they will be at the same point in the cosmic universe). The Zorons, even though are clever thieves, travel in one direction, and keep jumping exactly D units without stopping at any point. The Nova Corps can dial in the number of jumps they need to make (each of them exactly Z units), and reach the place almost instantly. They can then wait there until the Zorons arrive, and recover the Trident Crystal.
However, their wizard has told them that there may be situations where it is impossible for the Nova corps to be at the same distance as the Zorons.
As the planet is out of power currently, their supercomputers are shut down and they are not able to calculate the required information. As you are there from Earth they have approached you for help.
Note: Assume that the Cosmic universe is one dimensional.
Input
An integer T for number of test cases, followed by T test cases each one consisting of three numbers
- I :- initial distance of Zorons
- D:- distance covered in a single cosmic leap by Zoronion space craft.
- Z:- distance covered by Zandarian space crafts.
Output
Single number, the number of leaps required to catch the pirates, and if it is not possible to catch them, output will be -1
Constraints
1 ≤ I,D ≤ 1012
1≤Z≤109
Example 1
Input:
2
9512
5 7 9
Output:
2
6
Explanation:
The first line is 2, so T is 2, and there are 2 test cases.
In the first test case, The Zorons will initially be at 9 and then they will leap to 14,19 24….. The Nova Corps can take leaps of
12 and will catch them nearest at a distance 24, taking 2 leaps 12 and 24.
In the second test case, The Zorons will initially be at 5 and then they will leap to 12,19 26, 33, 40, 47, 54….. The Nova Corps
can take leaps of 9 and will catch them nearest at 54, taking 6 leaps.
Hence the output has 2 lines, 2 and 6.
Example 2
Input:
1
10 15 20
Output:
2
Explanation:
The first line is 1, so T is 1, and there is 1 test case.
The Zorons will initially be at 10, and jump in jumps of 15, landing at 25,40
The Nova Corps take leaps of 20, and arrive at 20, 40. Hence, they can meet at 40 after 2 leaps. The output is 2.
Spread the word and ask your every friend, junior, senior, batchmate, near and dear ones to Register to CodeVita! Click here to register.
Happy Coding!
We will be posting all the questions of CodeVita and also the Mock Tests.
We might not be able to publish all the questions. Keep sending your CodeVita’s question at circuitandcode@gmail.com

0 Comments
We are friendly, helpful and available. Reach out to us anytime and we will happily answer your quires. SEND US A MESSAGE OR FEEDBACK
Emoji