Calculating M(n)
and Optimizing M(n) Algorithms
Dave Purdum
Dr. Jonathan Webster
Definition
Define M(n) to be the number of distinct integers in the n by n multiplication table.
A027424
The number of different products calculated to create an n by n multiplication table.
M(4)
1 2 3 4 5 6 7 8 9
Multiplication table
Set of possible numbers in the multiplication table
= 9
There are 9 different integers in the 4 by 4 multiplication table.
Naive Algorithm
Directly calculate M(n) for a given value of n.
Time Complexity
Space Complexity
number of products that are calculated
number of possible values that can be crossed off
Optimizations
Optimizations
1
1 2 3
1 2 3 4 5 6
1 2 3 4 5 6 7 8 9
M(1) = 1
M(2) = 3
M(3) = 6
M(4) = 9
Tabulation
Repeated Evaluation
Calculating M(1), M(2), M(3), M(4)
Calculate 10 products
Calculate 20 products
Optimizations
Time Complexity
Space Complexity
Evaluation
Repeated Evaluation
Tabulation
Calculations
Memory Issues
Space
4
16
16 Bytes
100
10 000
9 KB
1 000 000
1 000 000 000 000
931 GB
10 000
100 000 000
1 MB
100 000
10 000 000 000
9 GB
Time
<< .001sec
30 min
.002 sec
20 sec
<< .001sec
Memory
Bottleneck
M(4) = 9
M(5) = ?
M(11)
M(12)
+ number of new integers =
Number of new distinct integers
Total integers in nth column
Number of integers in M(n-1) table
number of new integers in 12th row
number of integers in previous table
number of new integers in column
total number of integers in column
The number of distinct integers in a lattice bounded by the factorization of n.
clever algebra
number of new integers in 12th row
*
It just so happens that this pattern appears for n=12. This is generally more scattered.
*
1 2 3 4 5 6
Bounded by n!
Differences of M(n) Algorithm
Calculate the cumulative differences between M(n) and M(n-1) by calculating the delta function.
Time Complexity
Space Complexity
Evaluation
Tabulation
Calculating M(n)
and Optimizing M(n) Algorithms
Dave Purdum
Dr. Jonathan Webster
1 2 3 4 5
Calculate 41 products
Calculate 6 products
No Free Rows
First Row Free
First Row Free Algorithm
Calculate products in the lattice greater than the largest value in the first row.
Time Complexity
Space Complexity
Evaluation
Tabulation
Calculate 121 products
Calculate 55 products
No Free Rows
First Row Free
Calculate 15 products
Second Row Free
Getting Rows Free
Working in Modulo Classes
First Row Free
Second Row Free
"Third Row Free"
Modulo 1
Modulo 2
Modulo 6
Evens and Odds
0 mod 2 1 mod 2
Modulo n
Modulus by 2 and modulus by 3
Exploiting patterns in the first n rows
URC 2019 Presentation
By rutrum
URC 2019 Presentation
Presentation on April 12th for Butler University's Undergraduate Research Conference. This presentation addresses the different algorithms to calculate M(n) and ways to optimize those algorithms.
- 593