我的欧拉工程之路_5

Smallest multiple

Problem 5

2520 is the smallest number that can be divided by each of the numbers from 1 to 10 without any remainder.

What is the smallest positive number that is evenly divisible by all of the numbers from 1 to 20?

最小的乘数

问题 5

2520 是可以被1到10的整数整除的最小的整数.

求可以被1到20的整数整除的最小正整数?

public class Euler5
{
    public static void main(String[] args)
    {
        //列出小于20的所有素数
        int[] prime={2,3,5,7,11,13,17,19},primeCount=new int[8];
        for(int j=2;j<=20;j++)
        {
            for(int i=0;i<8;i++)
            {
                int k=1;
                while(Math.pow(prime[i],k)<=20)
                    k++;
                primeCount[i]=k-1;
            }
        }
        int smallMul=1;
        for(int i=0;i<8;i++)
        {
            smallMul*=Math.pow(prime[i],primeCount[i]);
        }
        System.out.println("最小的可被1到20的整数整除的数为"+smallMul);
    }
}


你可能感兴趣的:(欧拉工程,数学问题)