From 99c4b2d9980dd14e8c43ffbf00660047335ada4b Mon Sep 17 00:00:00 2001 From: Adrien Hopkins Date: Fri, 25 Aug 2023 08:55:30 -0500 Subject: Limit MTC calculation to < 2^32 This ensures the output can fit into a uint64. Also, calculating it at this stage is slow, and not calculating it can make the program nearly instant even for very large numbers! --- radix_info.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'radix_info.go') diff --git a/radix_info.go b/radix_info.go index f3aecce..daf62df 100644 --- a/radix_info.go +++ b/radix_info.go @@ -24,8 +24,13 @@ func main() { fmt.Println("2345 Rank:", factors.BasicRank(n)) if n < 1<<32 { printTypeMessage(factors.Type(uint32(n))) + // MTC(n) < n^2, so n < 2^32 ensures it fits in a uint64 + fmt.Println("Multiplication Table Complexity:", + factors.MTC(uint64(n))) + } else { + fmt.Printf("Multiplication Table Complexity ≤ %.4g\n", + float32(n) * float32(n - 2)) } - fmt.Println("Multiplication Table Complexity:", factors.MTC(n)) fmt.Printf("Natural Logarithm: %.2f\n", math.Log(float64(n))) } else { fmt.Println("Argument must be an integer above 1.") -- cgit v1.2.3