sympy
libraryPython sympy
is an open-source library used for symbolic mathematics. We can use pip
to install sympy
by using the following command.
pip install sympy
primenu()
methodThe primenu()
method is used to return the number of distinct prime factors for a given number. Here is how we can use the method in code.
sympy.primenu(n)
Note: Do not forget to
import sympy
at the start of your Python script.
In the above example, we’ve passed n
to the primenu()
method. n
has to be a positive integer. primenu()
will return the number of distinct prime factors for the given positive integer n
.
Here is a simple Python script that uses primenu()
.
import sympyn = 100print("The prime factors of %s are %s" % (n, sympy.primefactors(n)))print("The number of distinct prime factors for %s is %s" % (n, sympy.primenu(n)))
sympy
module so we can access its methods.n
, the variable we will pass to primenu()
.n
using the primefactors() method.n
obtained using the primenu()
method.