Question: A perfect square is an integer that can be expressed as the product of two equal integers. For example, 4 = 2 2 is a

A perfect square is an integer that can be expressed as the product of two equal integers. For example, 4 = 22 is a perfect square. An integer n is called primitive if it is divisible by no perfect square other than 1. For example, 15 is primitive but 12 is not, as 12 is divisible by 4 = 22 (a perfect square).

Write a program to find the largest even primitive integer n < t.

def factor(n): #Primes and Exponents(pae) pae = [] for k in range(2, math.ceil(n ** 0.5)): if n % k == 0: exponent = 1 while n % (k ** exponent) == 0: exponent += 1 pae.append([k, exponent-1]) n = n // (k ** (exponent-1)) if n != 1: pae.append([n,1]) return pae

def Isprimitive(n): pae = factor(n) for pair in pae: if pair[1] != 1: return False else: return True

def largestEvenPrimitive(n): if n % 2 == 1: n = n - 1 while (True): if Isprimitive(n): return n else: n = n - 2

print(largestEvenPrimitive(100))

this code prints 98, but I'm pretty sure is incorrect since 98 = 2 * 72.

Does this code address the question properly? is 98 the right output or can any changes be made to make it correct (if is not )?

Thank you

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!