Project Euler Solutions
factors.h
Go to the documentation of this file.
1 #ifndef DIVISORS_H
2 #define DIVISORS_H
3 
4 #include "iterator.h"
5 
6 #ifdef DOXYGEN
7 namespace c::include::factors {
8 #endif
9 
10 
16  uintmax_t target;
17  uintmax_t current;
19 };
20 
26 inline uintmax_t advance_factor_counter(factor_counter *fc) {
27  IterationHead(fc);
28  while (fc->target > fc->current) {
29  fc->current++;
30  if (fc->target % fc->current == 0) {
31  fc->exhausted = (fc->target == fc->current);
32  return fc->current;
33  }
34  }
35  return 0;
36 }
37 
42 inline factor_counter proper_divisors(uintmax_t target) {
44  return ret;
45 }
46 
50 uintmax_t proper_divisor_count(uintmax_t target);
51 inline uintmax_t proper_divisor_count(uintmax_t target) {
52  uintmax_t ret = 0;
53  factor_counter fc = proper_divisors(target);
54  while (!fc.exhausted) {
55  next(fc);
56  ret++;
57  }
58  return ret;
59 }
60 
61 #ifdef DOXYGEN
62 };
63 #endif
64 
65 #endif
Definition: factors.h:15
Definition: factors.h:7
#define IteratorInitHead(advance,...)
The base macro for all iterator initialization functions in this project.
Definition: iterator.h:111
#define IteratorTail(return_type, struct_type)
The base definition macro for all iterators in this project.
Definition: iterator.h:46
bool exhausted
An indicator that the iterator has stopped.
Definition: iterator.h:231
#define ExtendInit(name, value)
The extension macro for initializing more complicated Iterators.
Definition: iterator.h:168
#define next(state)
The macro to advance generic iterators.
Definition: iterator.h:180
uintmax_t current
Definition: factors.h:17
factor_counter proper_divisors(uintmax_t target)
Definition: factors.h:42
#define IterationHead(it)
The base macro for all iteration functions in this project.
Definition: iterator.h:74
uintmax_t proper_divisor_count(uintmax_t target)
Definition: factors.h:51
uintmax_t target
Definition: factors.h:16
uintmax_t advance_factor_counter(factor_counter *fc)
Definition: factors.h:26
An implementation of Python-like iterators and generators using macros to maintain static typing...