1 package com.sam.twisters.euler;
2 /* Problem 5 : Euler
3 * 2520 is the smallest number that can be divided by each of the numbers from 1 to 10 without any remainder.
4 * What is the smallest number that is evenly divisible (divisible without reminder) by all of the numbers from 1 to 20?
5 */
6
7 public class Prog5 {
8 /*Simple function to check if the divisor completely divides the divident*/
9 public static boolean isDivisble(int divident, int divisor) {
10 if(divident%divisor == 0){
11 return true;
12 }
13 else{
14 return false;
15 }
16 }
17
18 public static void main(String[] args)
19 {
20 long startTime = System.nanoTime();
21 boolean va = true;
22
23 /* Start looping though all the numbers and see if we can find one divisible by all numbers from 1 to 20.
24 */
25 int i = 1;
26 do{
27 va = true; //Assume that i is a valid answer to the puzzle
28 for(int d=1;d<=20;d++){
29 if (!isDivisble(i, d)){ //Yikes my assumption was wrong!
30 va = false;
31 }
32 }
33 i++;
34 }while(!va);
35 System.out.println(i);
36 long estimatedTime = System.nanoTime() - startTime;
37 System.out.println((float)estimatedTime/1000000000);
38 }
39 }