I have not been able to find any other questions on Math Exchange that answer this specific question. This is the most similar question that I have found, but the question is so poorly constructed that the answer is completely inadequate.
I have tried looking on Google to no avail. I did find this, but the formula seems incredibly inefficient and therefore insufficient. For instance, if we took the number 21...
21 % 1 = 0
21 % 2 = 1
21 % 3 = 0
21 % 4 = 1
21 % 5 = 1
21 % 6 = 3
21 % 7 = 0
...
Now imagine finding the common factors of numbers much greater than 21, such as 2,252 and 4,082... The method above would not be efficient whatsoever.
What I am trying to do is figure out the most efficient way to find all of the common factors of any given two numbers.
What is the most optimal method to find the common factors of any two numbers?
You could do a prime factorization of both numbers. By comparing the lists of prime factors, you get all common prime factors directly. All common non-prime factors are products of common prime factors.