ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Tue, 17 Aug 2021 14:54:31 +0200number of distinct prime factors of a numberhttps://ask.sagemath.org/question/58482/number-of-distinct-prime-factors-of-a-number/ I know how to write a function that counts the number of distinct prime factors of a number.
Does there exist an inbuilt function for this purpose?Mon, 16 Aug 2021 13:43:50 +0200https://ask.sagemath.org/question/58482/number-of-distinct-prime-factors-of-a-number/Answer by Max Alekseyev for <p>I know how to write a function that counts the number of distinct prime factors of a number. </p>
<p>Does there exist an inbuilt function for this purpose?</p>
https://ask.sagemath.org/question/58482/number-of-distinct-prime-factors-of-a-number/?answer=58495#post-id-58495Alternatively one can use `omega` (or `bigomega` to count prime factors with multiplicity) functions from GP:
sage: gp.omega(234)
3
sage: gp.bigomega(234)
4
Tue, 17 Aug 2021 14:54:31 +0200https://ask.sagemath.org/question/58482/number-of-distinct-prime-factors-of-a-number/?answer=58495#post-id-58495Answer by slelievre for <p>I know how to write a function that counts the number of distinct prime factors of a number. </p>
<p>Does there exist an inbuilt function for this purpose?</p>
https://ask.sagemath.org/question/58482/number-of-distinct-prime-factors-of-a-number/?answer=58484#post-id-58484There is a function to list the prime divisors or prime factors.
It is called `prime_divisors`, and aliased as `prime_factors`.
The `len` function can then give the number of prime factors.
sage: a = 234
sage: prime_divisors(a)
[2, 3, 13]
sage: len(prime_divisors(a))
3
sage: prime_factors(a)
[2, 3, 13]
sage: len(prime_factors(a))
3
The function `prime_divisors` and its alias `prime_factors`
also exist as methods of integers.
sage: a.prime_divisors()
[2, 3, 13]
sage: len(a.prime_divisors())
3
sage: a.prime_factors()
[2, 3, 13]
sage: len(a.prime_factors())
3
Mon, 16 Aug 2021 16:14:18 +0200https://ask.sagemath.org/question/58482/number-of-distinct-prime-factors-of-a-number/?answer=58484#post-id-58484