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?
import java.util.*;
import java.lang.*;
class Main
{
public static void main (String[] args) throws java.lang.Exception
{
Vector arr = new Vector();
for(int i=1;i<20;i++){
Vector tmp = factors(i);
//Merge the arrays
int j = 0, k = 0;
while(j < tmp.size() && k < arr.size()){
if(arr.elementAt(k).compareTo(tmp.elementAt(j)) == 0){
j++;k++;
}else if(arr.elementAt(k).compareTo(tmp.elementAt(j)) > 0){
//arr's is bigger than tmp's, so insert
arr.add(k, tmp.elementAt(j)); j++; k++;
}else{//tmp's is bigger than array's.
k++;
}
}
//append leftovers from tmp
for(int m=j; m factors(int z){
Vector result = new Vector();
int i = 2;
while(z > 1){
if(z % i == 0){
z/=i; result.add(new Integer(i));
}else{
i++;
}
}
return result;
}
}