Given an integer N, the task is to find the count of numbers from 1 to N which are divisible by all the numbers from 2 to 10.
Input: N = 3000
2520 is the only number below 3000 which is divisible by all the numbers from 2 to 10.
Input: N = 2000
Approach: Let’s factorize numbers from 2 to 10.
2 = 2
3 = 3
4 = 22
5 = 5
6 = 2 * 3
7 = 7
8 = 23
9 = 32
10 = 2 * 5
If a number is divisible by all the numbers from 2 to 10, its factorization should contain 2 at least in the power of 3, 3 at least in the power of 2, 5 and 7 at least in the power of 1. So it can be written as:
x * 23 * 32 * 5 * 7 i.e. x * 2520.
So any number divisible by 2520 is divisible by all the numbers from 2 to 10. So, the count of such numbers is N / 2520.
Below is the implementation of the above approach:
- 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 pairs of numbers from 1 to N with Product divisible by their Sum
- Count n digit numbers divisible by given number
- Count numbers in range L-R that are divisible by all of its non-zero digits
- Count natural numbers whose factorials are divisible by x but not y
- Count of all even numbers in the range [L, R] whose sum of digits is divisible by 3
- Count numbers in a range that are divisible by all array elements
- Count of Numbers in a Range divisible by m and having digit d in even positions
- Count of numbers between range having only non-zero digits whose sum of digits is N and number is divisible by M
- Count numbers which can be constructed using two numbers
- Sum of numbers from 1 to N which are divisible by 3 or 4
- Sum of first N natural numbers which are divisible by 2 and 7
- Sum of all numbers divisible by 6 in a given range
- Divisible by 37 for large numbers
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. 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.