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**.

**Examples:**

Input:N = 3000

Output:1

2520 is the only number below 3000 which is divisible by all the numbers from 2 to 10.

Input:N = 2000

Output:0

**Approach:** Let’s factorize numbers from 2 to 10.

2 = 2

3 = 3

4 = 2^{2}

5 = 5

6 = 2 * 3

7 = 7

8 = 2^{3}

9 = 3^{2}

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 * 2^{3}* 3^{2}* 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:

## C++

`// C++ implementation of the approach ` `#include <bits/stdc++.h> ` `using` `namespace` `std; ` ` ` `// Function to return the count of numbers ` `// from 1 to n which are divisible by ` `// all the numbers from 2 to 10 ` `int` `countNumbers(` `int` `n) ` `{ ` ` ` `return` `(n / 2520); ` `} ` ` ` `// Driver code ` `int` `main() ` `{ ` ` ` `int` `n = 3000; ` ` ` `cout << countNumbers(n); ` ` ` ` ` `return` `0; ` `} ` |

*chevron_right*

*filter_none*

## Java

`// Java implementation of the approach ` `class` `GFG ` `{ ` ` ` `// Function to return the count of numbers ` `// from 1 to n which are divisible by ` `// all the numbers from 2 to 10 ` `static` `int` `countNumbers(` `int` `n) ` `{ ` ` ` `return` `(n / ` `2520` `); ` `} ` ` ` `// Driver code ` `public` `static` `void` `main(String args[]) ` `{ ` ` ` `int` `n = ` `3000` `; ` ` ` `System.out.println(countNumbers(n)); ` `} ` `} ` ` ` `// This code is contributed by Arnab Kundu ` |

*chevron_right*

*filter_none*

## Python3

`# Python3 implementation of the approach ` ` ` `# Function to return the count of numbers ` `# from 1 to n which are divisible by ` `# all the numbers from 2 to 10 ` ` ` `def` `countNumbers(n): ` ` ` `return` `n ` `/` `/` `2520` ` ` `# Driver code ` `n ` `=` `3000` `print` `(countNumbers(n)) ` ` ` `# This code is contributed ` `# by Shrikant13 ` |

*chevron_right*

*filter_none*

## C#

`// C# implementation of the approach ` `using` `System; ` ` ` `class` `GFG ` `{ ` ` ` `// Function to return the count of numbers ` `// from 1 to n which are divisible by ` `// all the numbers from 2 to 10 ` `static` `int` `countNumbers(` `int` `n) ` `{ ` ` ` `return` `(n / 2520); ` `} ` ` ` `// Driver code ` `public` `static` `void` `Main(String []args) ` `{ ` ` ` `int` `n = 3000; ` ` ` `Console.WriteLine(countNumbers(n)); ` `} ` `} ` ` ` `// This code is contributed by Arnab Kundu ` |

*chevron_right*

*filter_none*

## PHP

`<?php ` `// PHP implementation of the approach ` ` ` `// Function to return the count of numbers ` `// from 1 to n which are divisible by ` `// all the numbers from 2 to 10 ` `function` `countNumbers(` `$n` `) ` `{ ` ` ` `return` `(int)(` `$n` `/ 2520); ` `} ` ` ` `// Driver code ` `$n` `= 3000; ` `echo` `(countNumbers(` `$n` `)); ` ` ` `// This code is contributed ` `// by Code_Mech. ` `?> ` |

*chevron_right*

*filter_none*

**Output:**

1

## Recommended Posts:

- Count of N-digit Numbers having Sum of even and odd positioned digits divisible by given numbers
- Count of numbers upto M divisible by given Prime Numbers
- 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 of all even numbers in the range [L, R] whose sum of digits is divisible by 3
- Count of numbers in a range that does not contain the digit M and which is divisible by M.
- Count numbers in range L-R that are divisible by all of its non-zero digits
- Count n digit numbers divisible by given number
- Count of N digit palindromic numbers divisible by 9
- Count the numbers with N digits and whose suffix is divisible by K
- Count natural numbers whose factorials are divisible by x but not y
- Count pairs of numbers from 1 to N with Product divisible by their Sum
- Count of numbers in range which are divisible by M and have digit D at odd places
- Count of Numbers in a Range divisible by m and having digit d in even positions
- Count numbers in a range that are divisible by all array elements
- Count numbers divisible by K in a range with Fibonacci digit sum for Q queries
- 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
- Count numbers which can be constructed using two numbers
- Sum of first K numbers which are not divisible by N

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.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.