This is my result:
2 x 3 x 5 x 7 x 11 x 13 x 17 x 19 x 23 x 29 x 31 x 37 x 41 x 43 x 47 x 53 x 59 x 61 = 3,982,538,761,641,808,742
divisable 2 : true
divisable 3 : false
divisable 5 : false
divisable 7 : false
divisable 11 : true
this is my code :
public static void main(String[] args) {
final ArrayList<Long> prime = prime();
System.out.println("size : " + prime.size());
long i = 1;
for (Long l : prime) {
System.out.print(" x "+l);
i *= l;
}
System.out.println(" = "+i);
long a[] = {2, 3, 5, 7, 11};
for (long b : a) {
System.out.printf("divisable %d : %b %n", b, i % b == 0 ? true : false);
}
}
public static ArrayList<Long> prime() {
ArrayList<Long> res = new ArrayList<>();
res.add(new Long(2));
next:
for (long i = 3; i < Byte.MAX_VALUE / 2; i += 2) {
//make Byte.MAX_VALUE / 3 will return true;
for (Long l : res) {
boolean b = true;
if (i % l == 0) {
continue next;
}
}
res.add(i);
}
return res;
}
Can anyone please explain why is that? Thank you :)