There are three planes , and . Plane will takeoff on every day i.e. , , and so on. Plane will takeoff on every day and plane will takeoff on every 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 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 , the number of test cases.
Then lines follow each containing four space-separated integers , , and 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 days.
Constraints
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 , the number of test cases.
Then lines follow each containing four space-separated integers , , and 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 days.
Constraints
SAMPLE INPUT
2 10 2 3 4 10 2 2 4
SAMPLE OUTPUT
4 0
Explanation
Sample test case :
Note that on days and plane can takeoff, on days and plane can takeoff.
Sample test case :
Note that there is no day on which there is no collision.
Note that on days and plane can takeoff, on days and plane can takeoff.
Sample test case :
Note that there is no day on which there is no collision.
Solution-
import java.util.*;
class Takeoff{
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int num=sc.nextInt();
int n,p,q,r,count;
for(int i=0;i<num;i++)
{
n=sc.nextInt();
p=sc.nextInt();
q=sc.nextInt();
r=sc.nextInt();
count = 0;
for(int j=1;j<=n;j++)
{
if(j%p == 0 && j%q != 0 && j%r != 0 ||
j%p != 0 && j%q == 0 && j%r != 0 ||
j%p != 0 && j%q != 0 && j%r == 0)
{
count++;
}
}
System.out.println(count);
}
}
}
Post a Comment