Sums and differences of factors

33 Views Asked by At

I am looking for a reference containing listing or table of the sums and differences of factors of positive integers; i.e. $\forall \space m_i\ge n_i,\space k=m_in_i$, list every $m_i\pm n_i$ for each $k\ge 1$. I know this is easily computable, but I am not a programmer and I can't readily generate by hand a list containing more than a few tens of entries. If anyone knows a place to look for such, I would be grateful. I haven't figured a way to query OEIS about this.

1

There are 1 best solutions below

2
On

MSE is perhaps the wrong place to ask/answer such a question... But nonetheless, here is a quick bit of Python code I wrote to solve this

from functools import reduce
import pandas as pd

def factors(n):    
    return set(reduce(list.__add__, 
                ([i, n//i] for i in range(1, int(n**0.5) + 1) if n % i == 0)))

def sumdifftable(n):
    table = []
    facts = list(factors(n))
    facts = facts[::-1]
    for pos,i in enumerate(facts):
        for j in facts[pos::]:
            table.append([i,j,(i+j),(i-j)])

    df = pd.DataFrame(table,columns=["mi","ni","mi+ni","mi-ni"])
    print(df.to_string(index=False))

Then for example, if we call

sumdifftable(12)

Then we get

mi  ni  mi+ni  mi-ni
12  12     24      0
12   6     18      6
12   4     16      8
12   3     15      9
12   2     14     10
12   1     13     11
 6   6     12      0
 6   4     10      2
 6   3      9      3
 6   2      8      4
 6   1      7      5
 4   4      8      0
 4   3      7      1
 4   2      6      2
 4   1      5      3
 3   3      6      0
 3   2      5      1
 3   1      4      2
 2   2      4      0
 2   1      3      1
 1   1      2      0

If you don't have Python installed locally, you can run this using an online IDE such as https://repl.it/languages/python3.