find all multiplicands and multipliers for a number

ravas ravas at outlook.com
Fri Apr 10 19:37:28 EDT 2015


def m_and_m(dividend):
    rlist = []
    dm = divmod
    end = (dividend // 2) + 1
    for divisor in range(1, end):
        q, r = dm(dividend, divisor)
        if r is 0:
            rlist.append((divisor, q))
    return rlist

print(m_and_m(999))
---
output: [(1, 999), (3, 333), (9, 111), (27, 37), (37, 27), (111, 9), (333, 3)]
---

How do we describe this function? 
Does it have an established name?
What would you call it?
Does 'Rosetta Code' have it or something that uses it?
Can it be written to be more efficient?
What is the most efficient way to exclude the superfluous inverse tuples?
Can it be written for decimal numbers as input and/or output?

Thank you!



More information about the Python-list mailing list