You are given the following function, which returns the set of all factors of a positive integer n:
def factors(n):
fact = set()
for f in range(1, n + 1):
if n % f == 0:
fact.add(f)
return fact
Write a function named common_factors that accepts two positive integers a and b as arguments and returns the set of common factors of the two numbers. This function must make use of factors.
The idea we are trying to bring out here is to make use of pre-defined functions whenever needed. Include the definition of factors in your answer as well, so that your code runs on its own.
You do not have to accept input from the user or print anything.
Example
common_factors(12, 18) -> {1, 2, 3, 6}
common_factors(7, 13) -> {1}
Implement this function:
def factors(n):
Write the function only — the arguments are read for you and the return value is printed automatically.
Arguments arrive as one Python literal per line, in this order: a, b.
Input
12
18
Output
{1, 2, 3, 6}