-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEuler3.cpp
More file actions
40 lines (35 loc) · 686 Bytes
/
Copy pathEuler3.cpp
File metadata and controls
40 lines (35 loc) · 686 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
#include <iostream>
#include <stdlib.h>
#include <vector>
#include <math.h>
using namespace std;
bool isprime(unsigned long int num){
if(num == 2 || num == 3){
return true;
}
if(num < 2){
return false;
}
for(unsigned long int i = 4; i < pow(num, .5); i++ ){
if(num%i == 0){
return false;
}
}
return true;
}
vector<int> factor(unsigned long int num){
vector<int> ret;
for(unsigned long int i = 1 ; i < pow(num, .5); i++){
if(num%i == 0){
if(isprime(i)){
ret.push_back(i);
}
}
}
return ret;
}
int main(){
unsigned long int to_factor = 600851475143;
vector<int> factors = factor(to_factor);
cout<<"largest factor: "<<factors[factors.size()-1];
}