Geeksforgeeks

Error

×

Leaderboard

Showing:

Handle | Score |
---|---|

@Ibrahim Nash | 5765 |

@blackshadows | 5715 |

@akhayrutdinov | 5111 |

@mb1973 | 4993 |

@Quandray | 4944 |

@saiujwal13083 | 4506 |

@sanjay05 | 3762 |

@marius_valentin_dragoi | 3516 |

@sushant_a | 3459 |

@verma_ji | 3341 |

@KshamaGupta | 3318 |

Complete Leaderboard | |

Handle | Score |

@aroranayan999 | 1276 |

@bt8816103042 | 739 |

@rohitanand | 495 |

@codeantik | 479 |

@shalinibhataniya1097 | 472 |

@amrutakashikar2 | 464 |

@thealchemist627 | 456 |

@shivanandp12345678910 | 453 |

@dalwainazism125 | 453 |

@akashkale117 | 453 |

@SherlockHolmes3 | 447 |

Complete Leaderboard |

Given a range [**m..n**]. You task is to find the number of integers divisible by either **a** or **b** in the given range.

**Example 1:**

Input:m =5,n =11,a =4,b =6Output:2Explanation:6 and 8 lie in the range and are also either divisible by 4 or 6.

**Example 2:**

Input:m =1,n =3,a =2,b =3Output:2Explanation:2 and 3 lie in the range and are also either divisible by 2 or 3.

**Your Task:**

You don't need to read input or print anything. Your task is to complete the function **numOfDiv()** which takes 4 Integers m, n, a, b as input and returns the count of integers in the range m..n which are divisible by either a or b.

**Expected Time Complexity:** O(log(max(a,b))

**Expected Auxiliary Space:** O(1)

**Constraints:**

1 <= m <= n <= 10^{5}

1 <= a,b <= 500

Login to report an issue on this page.

We strongly recommend solving this problem on your own before viewing its editorial. Do you still want to view the editorial?

Yes
Number of divisors in a given range

...