-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path3.cpp
More file actions
65 lines (51 loc) · 1.11 KB
/
3.cpp
File metadata and controls
65 lines (51 loc) · 1.11 KB
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#include <iostream>
#include <cmath>
#include <vector>
#include <ctime>
using namespace std;
bool is_prime(unsigned long long);
int main()
{
unsigned long long number = 600851475143;
long long num = 13195;
vector<unsigned long long> prime;
clock_t startTime = clock();
unsigned long long i;
int counter = 0;
for(i = 2; i < number; i++)
{
// cout << "i " << i << endl;
if(is_prime(i))
{
cout << " " << i;
while(number%i == 0)
{
prime.push_back(i);
cout << "Prime factor: " << i << endl;
number = number/i;
prime.push_back(number);
//break;
}
}
counter++;
}
double elapsedSeconds = (double)(clock() - startTime) / CLOCKS_PER_SEC;
cout << "\nCounter " << counter << endl;
cout << "\nMax Prime is " << prime.back() << endl;
cout << "RUN TIME: " << elapsedSeconds << endl;
}
bool is_prime(unsigned long long n)
{
unsigned long long i,sq,count=0;
if(n==1 || n==2)
return true;
if(n%2==0)
return false;
sq=sqrt(n);
for(i=2;i<=sq;i++)
{
if(n%i==0)
return false;
}
return true;
}