Let's Run
Practice
4.3 (3 votes)
Easy
Problem
90% Success 2595 Attempts 20 Points 2s Time Limit 256MB Memory 1024 KB Max Code

MANIT is organising a practice Marathon Let's Run in Sportomania. This is a non-competitive Marathon.
MANIT just provides the circular track of circumference 109+7 to the students and they can self evaluate them on the track. Track is bidirectional i.e. athelete can run in any direction.

Anurag, a enthusiastic athelete wants to evaluate himself and develope a strategy for his own evaluation.

Anurag starts his practice run at point S. He starts running at speed v . After each interval of time dt , he immediately increases his speed to n times and changes his direction. After some time T , he becomes tired and hence stop running.

Now Anurag calls his friend Ayush who was waiting for him at starting point to meet him at the same place where he stops. Anurag told his location to the Ayush. Find the minimum distance Ayush needs to travel?

Input:

The first line contains an integer, Q, denoting the number of queries.
The first and the only line of each query contain four space-separated integers: v, dt, n and T respectively as described in the statement.

Output:

For each query, find the minimum distance Ayush needs to travel in a single line.

Constraints:

1 ≤ Q ≤ 105
1 ≤ v,dt,n,T ≤ 109

Please login to use the editor

You need to be logged in to access the code editor

Loading...

Please wait while we load the editor

Loading...
Results
Custom Input
Run your code to see the output
Submissions
Please login to view your submissions
Similar Problems
Points:20
1 votes
Tags:
Modular arithmeticNumber TheoryHiringEasyMathematicsMathamatics
Points:20
30 votes
Tags:
Modular arithmeticad-hocNumber TheoryEasyMathematicsBrute-force search簡単
Points:20
1 votes
Tags:
Data StructuresBrute ForceMathModulus ArithmeticC++Number Theory