Title: Enter an integer n, output all the smallest factors of n, also called the element factor.
Where any number greater than 1 can be written as a product of several primes, we call these primes the number factor.
For example:
Input: 120
Output: 2 2 2 3 5
Input: 27
Output: 3 3 3
The Python Solver factor code is as follows:
#-*-Coding:utf-8-*-
def isprime (num):
Count = Num/2
While Count >1:
If num% count = 0:
Return False
Break
Else
Count = 1
Else
Return True
def getfactor (num):
L = []
If IsPrime (num):
return [num]
Count = Num/2
For n in range (2, Count + 1):
If num% n = 0 and IsPrime (n):
L.append (N)
return L
def primecal (num):
FAC = getfactor (num)
Mul = 1
For N in FAC:
Mul *= N
If mul = num:
return FAC
Else
return FAC + primecal (Num/mul)
if __name__ = = ' __main__ ':
Num=int (raw_input (' Please input a number:\r\n '))
Print sorted (primecal (num))
Sample execution Results:
Please input a number:
120
[2, 2, 2, 3, 5]