forked from rcheng9/ProjectEuler
-
Notifications
You must be signed in to change notification settings - Fork 0
/
SmallestMultiple.java
42 lines (38 loc) · 974 Bytes
/
SmallestMultiple.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
/**
* Project Euler problem for CS 196:
*
* Problem 5: Smallest multiple
* 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?
*
* @author Raymond Cheng
* @date Sunday, February 1, 2015
*
*/
public class SmallestMultiple {
/**
* @param args
*/
public static void main(String[] args) {
int possibleMultiple=20;
boolean isDivisible=true;
int currentDividingNumber=1;
int smallestMultiple=0;
while(smallestMultiple==0) {
while(currentDividingNumber<21 && isDivisible==true) {
if(possibleMultiple%currentDividingNumber!=0) {
isDivisible=false;
}
currentDividingNumber++;
}
if(isDivisible==true) {
smallestMultiple=possibleMultiple;
}
possibleMultiple++;
currentDividingNumber=1;
isDivisible=true;
}
System.out.println(smallestMultiple);
}
}