1 //题目:The prime factors of 13195 are 5, 7, 13 and 29.
2 //What is the largest prime factor of the number 600851475143 ?
1 #include<iostream>
2 using namespace std;
3 int main() {
4 long long N = 600851475143;//int和long都为32位,long long 为64位
5 int i;
6 bool isPrime(long long num);
7 long long res;
8 for(i=2; i<=N;i++){
9 while(isPrime(i) && N%i == 0.0){
10 N = N/i;
11 res = i;
12 }
13 }
14 cout << res << endl;
15 system("pause");
16 return 0;
17 }
18 bool isPrime(long long num){
19 int i=0;
20 for(i = 2; i*i <= num; i++){
21
22 if(num%i == 0.0)
23 return false;
24 }
25 return true;
26 }