From 3cfb1fdcbe83c1ee4adf8e370f0922ca41c472c6 Mon Sep 17 00:00:00 2001 From: Adrien Hopkins Date: Thu, 7 Sep 2023 13:15:40 -0500 Subject: Add ability to display specific totative digits Instead of just saying how many totative digits there are, the new -t flag allows the user to determine the specific digits. All totatives will end in one of these digits, and all primes are either factors or totatives. This feature is not useful in comparing radices, only learning one you have already chosen. Because there can be so many totatives (p - 1 of them for primes!), this is not displayed by default. The digit map (without -f) gives this information, and beyond its range every number will have more than 8 totatives, so do not use this flag if you only want the count. --- factors/totative.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'factors/totative.go') 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 +} -- cgit v1.2.3