diff options
| author | Adrien Hopkins <adrien.p.hopkins@gmail.com> | 2023-08-25 08:55:30 -0500 |
|---|---|---|
| committer | Adrien Hopkins <adrien.p.hopkins@gmail.com> | 2023-08-25 08:55:30 -0500 |
| commit | 99c4b2d9980dd14e8c43ffbf00660047335ada4b (patch) | |
| tree | 400aac6fc6694327454ba91e6fe6973282106769 /factors/mtc.go | |
| parent | 24a8dde3a708b0cd95007d940e8957b21df40055 (diff) | |
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!
Diffstat (limited to 'factors/mtc.go')
| -rw-r--r-- | factors/mtc.go | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/factors/mtc.go b/factors/mtc.go index d008ca3..522a35c 100644 --- a/factors/mtc.go +++ b/factors/mtc.go @@ -3,15 +3,15 @@ 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++ { +func MTC(n uint64) uint64 { + mtc := uint64(0) + for i := uint64(2); i <= n - 2; i++ { mtc += n / gcd(i, n) } return mtc } -func gcd(a, b uint) uint { +func gcd(a, b uint64) uint64 { for b > 0 { a, b = b, a % b } |
