-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproblem5.cpp
More file actions
50 lines (44 loc) · 777 Bytes
/
Copy pathproblem5.cpp
File metadata and controls
50 lines (44 loc) · 777 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#include <iostream>
using namespace std;
int main(){
unsigned long n = 600851475143;
unsigned long factor = 2;
unsigned long lastFactor = 1;
while ( n > 1){
if (n % factor == 0){
lastFactor = factor;
n = n / factor;
while (n % factor==0)
n = n / factor;
}
factor=factor+1;
}
cout<<lastFactor<<endl;
return 0;
}
//int main(){
// unsigned long limit = 600851475143;
// unsigned long tmp = limit;
// unsigned long i,j;
//
// for ( i = 2; i < limit/2; i++ ) {
//
// for ( j = 2; j <= i/2; j++ ) {
//
// if ( i % j == 0 ) break;
//
// }
//
// if ( j > i / 2 ) {
// while (tmp % i ==0)
// tmp /= i;
//
// if (tmp ==1){
// cout<<i<<endl;
// break;
// }
// }
//
// }
// return 0;
//}