This article mainly describes the Python implementation of the quality factorization algorithm, involving Python mathematical operations related operation skills, the need for friends can refer to the following
In this paper, we describe the quality factorization algorithm implemented by Python. Share to everyone for your reference, as follows:
Originally wanted to implement an other basic mathematical algorithm problem, but found in the implementation must first complete the decomposition of the mass-based algorithm.
Did not go online to find what is better than the solution algorithm, purely according to their own understanding of writing a tentative solution algorithm. This is the Guess-try method that Professor mentions in the MIT Open class. The code is implemented as follows:
#!/usr/bin/pythondef primenum (num): r_value =[] for i InRange (2,num+1): For Jin Range (2,i): ifi% J = = 0 : break Else: r_value.append (i) returnr_valuedef primefactorsolve (num,prime_list): For N Inprime_list: ifnum% n = = 0: return[n,num/n]def primepisor (num): prime_range= primenum (num) ret_ Vale =[] and numnot in Prime_range: factor_list= primefactorsolve (num,prime_range) ret_vale.append (Factor_list[0]) Num =factor_list[1] else: ret_vale.append (num) printret_valeprimepisor (120)
The results of the program execution are as follows:
E:\WorkSpace\01_ programming Language \03_python\python_exp07>pythonpython_exp07.py
[2, 2, 2, 3, 5]
The extraction tests the other data, from the simple example calculation, the result is accurate.