#OK to post homework #AJ Bu, January 22, 2024, Assignment 2 ############## PROBLEM 3 ############## #MyIfactor(n): that inputs a positive integer and #outputs a list of its prime factors (with repetition), in weakly increasing order. #For example, MyIfactor(100) #outputs [2,2,5,5] MyIfactor:=proc(n) local L,p,n1:: if n=1 then RETURN([]): fi: if isprime(n)=true then RETURN([n]): fi: L:=[]: p:=2: n1:=n: while isprime(n1)=false do while type(n1/p,integer)=false do p:=nextprime(p): od: L:=[op(L),p]: n1:=n1/p: od: L:=[op(L),n1]: end: #This homemade procedure was slightly slower than Maple's ifactor procedure for some #of the values I tested. #time(MyIfactor(9239193239134)) # 0. #time(ifactor(9239193239134)) # 0. #time(MyIfactor(n)) # 0.015 #time(ifactor(n)) # 0. #n:=rand(10^16..10^17)() # n := 46650214228473823 #time(MyIfactor(n)) # 0. #time(ifactor(n)) # 0. #n:=rand(10^16..10^17)() # n := 79920570985588261 #time(MyIfactor(n)) # 0.734 #time(ifactor(n)) # 0. #n:=rand(10^16..10^17)() # n := 90830494221539044 #time(MyIfactor(n)) # 0.015 #time(ifactor(n)) # 0. #time(ifactor(n)) # 0. #n:=rand(10^16..10^17)() # n := 82883713678695162 #time(MyIfactor(n)) # 0. #time(ifactor(n)) # 0. #n:=rand(10^16..10^17)() # n := 35144326511170833 #time(MyIfactor(n)) # 0.015 #time(ifactor(n)) # 0.