projectEuler pro3
Largest prime factor
Problem 3
The prime factors of 13195 are 5, 7, 13 and 29.
What is the largest prime factor of the number 600851475143 ?
JAVA:
import java.math.BigDecimal; //引入这个包
public class P003 {
public static void main(String[] args){
long out = 0;
long div = 0;
long ans = 0;
BigDecimal bignume = new BigDecimal("600851475143");
double a = Math.sqrt((double)bignume.longValue());
for(int i=1;i<a;i++){
if(bignume.longValue()%i==0){
out = i;
div = bignume.longValue()/i;
if(isyinzi(out)&&isyinzi(div)){
ans = Math.max(out, div);
}else if(isyinzi(out))
ans = Math.max(out, ans);
else if(isyinzi(div))
ans = Math.max(ans, div);
}
}
System.out.print(ans+"\n");
System.out.print(div);
}
public static boolean isyinzi(long a){
for(long i=2;i*i<a;i++){
if(a%i==0)
return false;
}
return true;
}
}
posted on 2013-10-08 21:27 Monster_Ch 阅读(84) 评论(0) 收藏 举报
浙公网安备 33010602011771号