Repository navigation
Expand file tree
/
Copy pathfactor_iterator.h
More file actions
69 lines (60 loc) · 1.89 KB
/
Copy pathfactor_iterator.h
File metadata and controls
69 lines (60 loc) · 1.89 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
69
// Licensed under the MIT License.
#include "sieve_iterator.h"
/** Iterates over the prime factors of a positive integer. */
struct FactorIterator
{
struct SieveIterator iterator;
long long current;
long long remainder;
int exponent;
};
/** Iterates over the prime factors of a positive integer. */
typedef struct FactorIterator* FactorIterator;
/**
* Provides an iterator over the prime factors of `n`.
*
* @param iterator when this method returns, contains the iterator. This
* argument is passed uninitialized.
* @param n the number whose factors to enumerate.
* @param primes the prime sequence.
*/
void factor_begin(FactorIterator iterator, long long n, Sieve primes);
/**
* Returns a value indicating whether the iterator can advance to the next prime
* factor.
*
* @param iterator the iterator.
* @return `true` if the iterator can successfully advance to the next factor;
* `false` if there are no more factors.
*/
bool factor_end(FactorIterator iterator);
/**
* Advances the iterator to the next prime factor.
*
* @param iterator the iterator.
*/
void factor_next(FactorIterator iterator);
/**
* Returns the number of divisors of a positive integer.
*
* @param n the number whose divisors to count.
* @param primes the prime sequence.
* @return The number of divisors of `n`.
*/
int factor_divisor_count(long long n, Sieve primes);
/**
* Computes the sum of the divisors of a positive integer.
*
* @param n the number whose divisors to sum.
* @param primes the prime sequence.
* @return The sum of the divisors of `n`.
*/
int factor_divisor_sum(long long n, Sieve primes);
/**
* Computes the sum of the prime factors of an integer.
*
* @param n the number whose prime factors to sum.
* @param primes the prime sequence.
* @return The sum of the prime factors of `n`.
*/
int factor_sum(long long n, Sieve primes);