Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

using Python Problem 4: More factoring 4a. The trial_division function returns t

ID: 3711591 • Letter: U

Question

using Python

Problem 4: More factoring 4a. The trial_division function returns the smallest prime factor of the input integer, e.g. trial division 15)-3. Use it to find the smallest prime factor of 4a.1.120 4a.2. 21931 4b. Write a function tdfactor(N) that takes as input an integer N and then tries to factor it by doing the following: uses trial_divison(N) to find the smallest prime factor d of N and then replaces N by N/d and starts over -tdfactor(N) must return a non-decreasing list of prime factors of N counting multiplities, e.g. tdfactor(12) returns [2,2,3, tdfactor(100) returns [2,2,5,5, etc Your function has to be reasonably efficient, e.g. it can't take more than one second to solve 4c.3 -Other than trial_division), you are not allowed to use any other built-in Sage functions that are not available in Python 4c. Use your function tdfactor(N) from 4b to factor the same integers as in problem 3d. -4c.1.12 -4c.2. 120 -4c.3. 7391739173919996

Explanation / Answer

xlist=[]
miniList=[]
class CalFactors(object):
#4.a.1&2
def trial_division(x):
global xlist
print("The factors of",x,"are:")
for i in range(2, int(x) + 1):
if x % i == 0:
xlist.append(i)
#print(xlist)  
miniFact=min(xlist)
return miniFact
#4.b&c
def tdfactor(num2,num3):
global miniList
mininum2=num2/num3
miniList.append(mininum2)
return mininum2  
print(miniList)

choice=input("Enter your choice: 1. Calculate minimum factor. 2. Calculate tdfactor value ")
if int(choice)==1:
num = (2 **3)-1
  
print("minimum factor is:",CalFactors.trial_division(num))

if int(choice)==2:
input2=input("Enter number N for tdfactor function ")
while((input2)!=1):
result=CalFactors.trial_division(input2)
divResult=CalFactors.tdfactor(input2,result)
input2=divResult