A number is Expensive if the number of digits of its prime factorization (including exponents greater than 1) is greater than the total digits of the number itself. Given an integer Implement a function that returns a string: If the number of digits of the prime factorization (including exponents greater than 1) is equal to the number of digits of N print Equal If the number of digits of the prime factorization (including exponents greater than 1) is lower than the number of digits of N print Cheap print None of the above if none of the two above conditions is true
Answer to this question:
def factorization(n):
i = 2
ret = []
while i * i <= n:
while n % i == 0:
ret.append(i)
n = n / i
i = i + 1
if n > 1:
ret.append(int(n))
return ret
n=int(input("Please enter an integer: "))
fac_list=factorization(n)
if len(str(n))==len(fac_list):
print('Eqal')
else:
if len(str(n))<len(fac_list):
print('Cheap')
else:
print('None')
Comments
Leave a comment