precisely a minutes to swim across the whole pool and return, precisely b minutes for the subsequent swimmer and c minutes for the third. Thus, the main swimmer will be on the left half of the pool after 0, a, 2a, 3a, ... minutes after the beginning time, the subsequent one will be at 0, b, 2b, 3b, ... minutes, and the third one will be on the left half of the pool after 0, c, 2c, 3c, ... minutes.

C++ for Engineers and Scientists
4th Edition
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Bronson, Gary J.
Chapter5: Repetition Statements
Section: Chapter Questions
Problem 2PP: (Mechanics) The deflection at any point along the centerline of a cantilevered beam, such as the one...
icon
Related questions
Question

Correct answer will be upvoted else downvoted. Computer science.

 

 It takes the principal swimmer precisely a minutes to swim across the whole pool and return, precisely b minutes for the subsequent swimmer and c minutes for the third. Thus, the main swimmer will be on the left half of the pool after 0, a, 2a, 3a, ... minutes after the beginning time, the subsequent one will be at 0, b, 2b, 3b, ... minutes, and the third one will be on the left half of the pool after 0, c, 2c, 3c, ... minutes. 

 

You went to the left half of the pool precisely p minutes after they began swimming. Decide how long you need to stand by before one of the swimmers shows up at the left half of the pool. 

 

Input 

 

The primary line of the input contains a solitary integer t (1≤t≤1000) — the number of experiments. Next t lines contains experiment portrayals, one for every line. 

 

Each line contains four integers p, a, b and c (1≤p,a,b,c≤1018), time in minutes after the beginning, when you went to the pool and times in minutes it take the swimmers to cross the whole pool and return. 

 

Output 

 

For each experiment, output one integer — how long you need to stand by (in minutes) before one of the swimmers shows up at the left half of the pool.

 

 

Expert Solution
steps

Step by step

Solved in 3 steps with 1 images

Blurred answer
Knowledge Booster
Fundamentals of Boolean Algebra and Digital Logics
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ for Engineers and Scientists
C++ for Engineers and Scientists
Computer Science
ISBN:
9781133187844
Author:
Bronson, Gary J.
Publisher:
Course Technology Ptr