Takeoff
Practice
3.9 (90 votes)
Arrays
Brute Force search
Data structures
Easy
Hash tables
Implementation
Math
One Dimensional
Problem
81% Success 12313 Attempts 20 Points 1s Time Limit 256MB Memory 1024 KB Max Code

There are three planes $$A$$, $$B$$ and $$C$$. Plane $$A$$ will takeoff on every $$p^{th}$$ day i.e. $$p$$, $$2p$$, $$3p$$ and so on. Plane $$B$$ will takeoff on every $$q^{th}$$ day and plane $$C$$ will takeoff on every $$r^{th}$$ day. There is only one runway and the takeoff timing is same for each of the three planes on each day. Your task is to find out the maximum number of flights that will successfully takeoff in the period of $$N$$ days.

Note: If there is collision between the flights no flight will take off on that day.

Input Format
The first line of the input contains a single integer $$T$$, the number of test cases.
Then $$T$$ lines follow each containing four space-separated integers $$N$$, $$p$$, $$q$$ and $$r$$ as denoted in the statement.

Output Format
For each test case print a single integer representing the maximum number of flights that will successfully takeoff in the period of $$N$$ days.

Constraints
$$1 \le T \le 10$$
$$1 \le N, p, q, r \le 10^5$$

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
193 votes
Tags:
AlgorithmsApprovedEasyImplementationOpen
Points:20
65 votes
Tags:
ArraysC++1-DData StructuresGreedy AlgorithmsBasics of Greedy AlgorithmsMath
Points:20
280 votes
Tags:
ApprovedData StructuresEasyOpenQueue