📌  相关文章
📜  计算可以被2到10的所有数字整除的数字

📅  最后修改于: 2021-05-05 00:48:18             🧑  作者: Mango

给定整数N ,任务是找到1N的数量计数,该数量可以被210的所有数字整除。

例子:

方法:让我们将2到10的数字分解。

如果一个数字可以被210的所有数字整除,则其因式分解应至少包含2的幂, 3的幂, 3的至少2的幂, 5的整数和7的至少1的幂。因此可以写成:

因此,任何可以被2520整除的数字都可以被210的所有数字整除。因此,此类数字的数量为N / 2520

下面是上述方法的实现:

C++
// C++ implementation of the approach
#include 
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;
}


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


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


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


PHP


Javascript


输出:
1