欧拉项目 problem3(求最大质因素)

 

The prime factors of 13195 are 5, 7, 13 and 29.

What is the largest prime factor of the number 600851475143 ?

 

简单的翻译过来就是求600851475143这个数的最大质因素。别小看一道小小的这个题目,算法还是有蛮多的。有好的思路,解题还是比较快的。


连接:http://projecteuler.net/index.php?section=problems&id=3


public class Problem3{

public static void main(String args[]) {
long x=600851475143L;
long a = 2;
while (x > 1) {
if ((x % a) == 0) {
x = x / a;
} else {
a++;
}
}
System.out.println(a);
}

}

你可能感兴趣的:(项目)