int num = 127 // could be as large as 999999937
int divby = 2;
while(num % divby != 0) {
divby++;
}
System.out.println(divby);
int num = 127 // could be as large as 999999937
int divby = 2;
if (num % divby !=0) {
divby = 3;
while(num % divby != 0) {
divby+=2;
}
}
System.out.println(divby);
ASKER
int sqrt = (int)Math.sqrt(num); // find sqrt of current large number
int num = 127 // could be as large as 999999937
int divby = 2;
if (num % divby !=0) { // can we divide large number by 2?
// no? ok, lets check the other odd numbers upto sqrt
for(divby = 3;num%divby != 0;divby+=2)
{ if(divby>sqrt+1){divby=num-2;} }
}
}
System.out.println(divby);
Java is a platform-independent, object-oriented programming language and run-time environment, designed to have as few implementation dependencies as possible such that developers can write one set of code across all platforms using libraries. Most devices will not run Java natively, and require a run-time component to be installed in order to execute a Java program.
TRUSTED BY
no sense to try those which end in 5 and 10