summaryrefslogtreecommitdiff
path: root/factors
diff options
context:
space:
mode:
Diffstat (limited to 'factors')
-rw-r--r--factors/totative.go14
1 files changed, 14 insertions, 0 deletions
diff --git a/factors/totative.go b/factors/totative.go
index 680cc26..abbbe89 100644
--- a/factors/totative.go
+++ b/factors/totative.go
@@ -17,3 +17,17 @@ func Totient(n uint) uint {
return num * (n / denom)
}
+
+// TotativeDigits returns a slice containing every number less than r
+// that is a totative of r (shares no factors with r).
+func TotativeDigits(r uint32) []uint32 {
+ digits := make([]uint32, Totient(uint(r)))
+ totativesFound := 0
+ for d := uint32(0); d < r; d++ {
+ if gcd(d, r) == 1 {
+ digits[totativesFound] = d
+ totativesFound++
+ }
+ }
+ return digits
+}