-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBoundedFactorizations.h
60 lines (44 loc) · 1.9 KB
/
BoundedFactorizations.h
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
#pragma once
#include <cstdint>
#include <memory>
#include <vector>
#include "BoundedPrimeSets.h"
#include "PrimePower.h"
using primes_t = std::vector<std::uint64_t>;
using factorization_t = std::vector<PrimePower<std::uint64_t, std::uint32_t>>;
// Iterates through a specified set of prime factorizations.
// The set is constrained by an upper bound on the integer corresponding
// to each factorization, and by a predetermined pool of primes
// from which to construct the factorizations.
class BoundedFactorizationIterator
{
private:
// The upper bound.
std::uint64_t upperBound;
// The prime pool.
std::shared_ptr<const primes_t> primePool;
// The current factorization.
std::shared_ptr<factorization_t> factorization;
// The set of primes appearing in the current prime factorization.
std::unique_ptr<BoundedPrimeSetIterator> bpsi;
// The integer corresponding to the current factorization.
std::uint64_t n;
// Whether the iterator is in the end state.
bool isEnd;
public:
// Constructs a BoundedFactorizationIterator with given upper bound.
// The prime pool is constructed to be the set of primes less than the upper bound.
BoundedFactorizationIterator (std::uint64_t upperBound);
// Constructs a BoundedFactorizationIterator with given upper bound and prime pool.
BoundedFactorizationIterator (std::uint64_t upperBound, std::shared_ptr<const primes_t> primePool);
// Returns the current factorization.
std::shared_ptr<const factorization_t> Factorization () const;
// Returns the integer corresponding to the current factorization.
std::uint64_t N () const;
// Moves the iterator forward one step.
void operator++ ();
// Returns whether the iterator is in the end state.
bool IsEnd () const;
// Returns the Moebius function of the integer corresponding to the current factorization.
std::int32_t MoebiusN () const;
};