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

in Python Problem 3: Factoring 3a. The function is prime (already defined) tests

ID: 3711564 • Letter: I

Question

in Python

Problem 3: Factoring 3a. The function is prime (already defined) tests if a number is prime. Use it to test if the following integers are prime -??. 1 . 2017 -3a.2. 2015 -3a.3. 5089499053 158977852651592594959255499618560261658305128152749732980638928693867617555084993160281949064053399342129943623386301078583622070862781989642880265570519636898574116 9061589392187723374511476815445516292269023831265631925174400849066851 3b. Does 991 divide the number n from 3a.4? (Hint: a%b computes the remainder of a divided by b. One can test if b divides a by testing if a%bs equal to ) 3c. Write a function hsfactor(N) that takes as input a positive integer N and then tries to factor it the high-school way by going through all integers i

Explanation / Answer


def isprime(n) :
if n > 1 :
for i in range(2,n) :
if (n%i)== 0 :
print("it is a not a prime number")
return True
else :
print("it is not a prime number")
return False
def isdiv_from991(n) :
divisor =991
if (n%divisor)== 0 :
print("number is divisor")
else :
print("number is not a divisor if 991")
def hasFactor(n) :
factor=[]
while n%2 ==0 :
factor.append(2)
i=3
while i < math.sqrt(n) :
if n% i == 0 :
factor.append(i)
n=n/i
i+=2
return factor
if __name__=="__main__" :
isprime(2017)
isprime(2015)
isprime(5089499053)
isprime(1589778526515922595959255499618560261658305128152749732980638928693867617555084499316028194906405339
9342129943622338630107858362207086278198964288026557051963689997411690615893928177233745114768154455162922
6902831265631925174400849066351)
isdiv_from991(1589778526515922595959255499618560261658305128152749732980638928693867617555084499316028194906405339
9342129943622338630107858362207086278198964288026557051963689997411690615893928177233745114768154455162922
6902831265631925174400849066351)
print(hasFactor(12) )
print(hasFactor(120))
print(hasFactor(739173919996))
#please inforn if something is not correct