I'm needing a little help with this:
public class BiggestPrimeFactor{
public static void main(String[] args){
long biggest=0L;
for(long i=2L; i<=600851475143L; i++){
if(600851475143L%i==0){
for(int l=1; l<=Math.sqrt(i); l++){
if (i%l==0){
break;
} else{
biggest=i;
}
}
}
}
System.out.println(biggest);
}
}//end of BiggestPrimeFactor
I don't know if it is okay or wrong, but it is taking way too much (more than half an hour then I got tired and closed command-line)...
Can you help or at least tell me if it is fine?
thanks!
i could solve it!!
this is what it does look like
public class BiggestPrimeFactor{
public static void main(String[] args){
long x=600851475143L;
long biggest=0L;
for(long i=2L; i<=x; i++){
for(long l=1L; l<=Math.sqrt(i); l++){
if(l%i==0){
break;
} else{
while(x%i==0){
x=x/i;
biggest =i;
}
}
}
}
System.out.println(biggest);
}
}//end of BiggestPrimeFactor
and it took really little time! =P thanks for your help!