-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprob3.cpp
More file actions
69 lines (56 loc) · 1.44 KB
/
prob3.cpp
File metadata and controls
69 lines (56 loc) · 1.44 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
66
67
68
#include <iostream>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <cstdint>
#include <cassert>
class primes_list
{
public:
uint64_t* list;
int size;
primes_list(uint64_t upper = 100)
{
list = new uint64_t[upper + 1];
for (uint64_t k = 0; k <= upper; k++)
{
if (k == 1)
list[k] = 0;
else
list[k] = k;
}
for (uint64_t p = 2; p <= upper; p++)
for (uint64_t j = p + p; j <= upper; j += p)
list[j] = 0;
for (uint64_t i = 0; i <= upper; i++)
{
if (list[i] != 0)
{
list[size] = list[i];
size++;
}
}
}
~primes_list()
{
delete list;
}
};
int main(int argc, char *argv[])
{
uint64_t input = atoll(argv[1]);
uint64_t max;
primes_list* primes = new primes_list(10000);
for (int k = 0; k < primes->size; k++)
{
uint64_t current = primes->list[k];
while (input % current == 0)
{
input /= current;
max = current;
}
}
assert(input == 1);
std::cout << "Largest prime factor of number " << argv[1] << " is: " << max << std::endl;
return 0;
}