Divisible Numbers

4.4

5 votes
Number Theory, Mathematics, GCD, Math
Problem

You are given 4 positive integers N, a, b, and c
Your task is to calculate the total number of integers from 1 to N that are divisible by either a, b, or c.

Input Format

  • The first line of the input data contains the single integer T denoting the number of test cases.
  •  Each test case contains four integers N, a, b and c.

Output Format:

  • For each test case output the total number of intergers from 1 to N which are divisible by either a, b or c.

Constraints

  • 1T100
  • 1N109
  • 1a,b,cN
     
Time Limit: 2
Memory Limit: 256
Source Limit:
Explanation

In the first test case, there are total 4 numbers (5, 7, 9, 10) which are divisble by 5, 7 or 9.

In the second test case, there are total 7 numbers (3, 5, 6, 9, 10, 12, 15) which are divisble by 3, 5 or 10.
 

Editor Image

?