Original textbook question (number theory course):
> The product of the positive integer divisors of a positive integer n is 729. Find n.
Actual model input/prompt:
> Write a function which finds the divisors (including 1 and itself) of the input and multiplies them together. Iterate over all possible integers until it finds an input where the product is 729.
Model output program:
def divisors(n):
divisors = []
for i in range(1, n+1):
if n % i == 0:
divisors.append(i)
return divisors
def product(n):
return reduce(lambda x, y: x*y, n)
def find_n(n):
for i in range(1, n):
if product(divisors(i)) == 729:
return i
print find_n(1000000)
Not only is the prompt explaining exactly what to do, it's using an iterative approach instead of an analytical approach, as might be expected from a math class.Note: any errors in the program are my own transcribing error.