I have been going through the Euler project problems one by one every day and asking whatever questions I have on this website. The problem description is commented out in the code. This time around, I don't have any particular problems with my code, but I was wondering if there is any way to improve or optimize it. I am a beginner, so it would be helpful to hear any suggestions. Here is the code in Java:
//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?
int smallest = 0;
for(int num = 2520; num < 1000000000; num += 2520) {
boolean isMultiple = true;
for (int multiple = 20; multiple >= 11; multiple--) {
if (num % multiple != 0) {
isMultiple = false;
break;
}
}
if (isMultiple) {
smallest = num;
break;
}
}
System.out.println("The LCM of all the numbers between one and twenty is : " + smallest);
question from:
https://stackoverflow.com/questions/65867778/could-my-solution-to-the-5th-euler-projectjava-problemlcm-of-1-through-20-be 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…