From 547c63fbf0c6dd673e8caf83ea7f9eeb679b5f5c Mon Sep 17 00:00:00 2001 From: Adrien Hopkins Date: Mon, 21 Aug 2023 09:35:27 -0500 Subject: Add MTC to output (MTC = Multiplication Table Complexity) --- factors/mtc.go | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 factors/mtc.go (limited to 'factors/mtc.go') diff --git a/factors/mtc.go b/factors/mtc.go new file mode 100644 index 0000000..d008ca3 --- /dev/null +++ b/factors/mtc.go @@ -0,0 +1,19 @@ +package factors + +// MTC returns the multiplication table complexity of a radix n. +// This is an estimate of how difficult it is to learn a radix's +// multiplication table. +func MTC(n uint) uint { + mtc := uint(0) + for i := uint(2); i <= n - 2; i++ { + mtc += n / gcd(i, n) + } + return mtc +} + +func gcd(a, b uint) uint { + for b > 0 { + a, b = b, a % b + } + return a +} -- cgit v1.2.3