Tuesday, July 17, 2012

java code for eular project problem5

PROBLEM


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?

ANSWER


232792560

JAVA CODE


public class Problem5 {
public static void main(String[]args){
int ans=0;
for (int i = 100000000; i <1000000000; i++) {
boolean state=true;
for (int j = 3; j <21; j++) {
ans=i;
if(i%j!=0||i==9999999){
//ans=-1;
state=false;
break;
}

}

if(state){
break;
}
}
System.out.println(ans);
}
}


0 comments:

Post a Comment