Given four integers A, B, C and D. The task is to find the count of integers in the range [A, B] that are not divisible by C and D .
Input: A = 4, B = 9, C = 2, D = 3
5 and 7 are such integers.
Input: A = 10, B = 50, C = 4, D = 6
Approach: First include all the integers in the range in the required answer i.e. B – A + 1. Then remove all the numbers which are divisible by C and D and finally add all the numbers which are divisible by both C and D.
Below is the implementation of the above approach:
Don’t stop now and take your learning to the next level. Learn all the important concepts of Data Structures and Algorithms with the help of the most trusted course: DSA Self Paced. Become industry ready at a student-friendly price.
- Count integers in a range which are divisible by their euler totient value
- Number of integers in a range [L, R] which are divisible by exactly K of it's digits
- Ways to form an array having integers in given range such that total sum is divisible by 2
- Count of m digit integers that are divisible by an integer n
- Count of integers of the form (2^x * 3^y) in the range [L, R]
- Count the numbers divisible by 'M' in a given range
- Count numbers in range 1 to N which are divisible by X but not by Y
- Count numbers in range L-R that are divisible by all of its non-zero digits
- Count of all even numbers in the range [L, R] whose sum of digits is divisible by 3
- Count of numbers in range which are divisible by M and have digit D at odd places
- Minimum elements to be added in a range so that count of elements is divisible by K
- Count of numbers between range having only non-zero digits whose sum of digits is N and number is divisible by M
- Count numbers in a range with digit sum divisible by K having first and last digit different
- Sum of last digit of all integers from 1 to N divisible by M
- Count of integers in a range which have even number of odd digits and odd number of even digits
- Number of substrings divisible by 4 in a string of integers
- Number of substrings divisible by 6 in a string of integers
- Count the number of pairs (i, j) such that either arr[i] is divisible by arr[j] or arr[j] is divisible by arr[i]
- Find sum in range L to R in given sequence of integers
- Most frequent factor in a range of integers
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.