Ask Your Question

number of distinct prime factors of a number

asked 2021-08-16 13:43:50 +0200

aakkbb gravatar image

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?

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted

answered 2021-08-16 16:14:18 +0200

slelievre gravatar image

There 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))

sage: prime_factors(a)
[2, 3, 13]
sage: len(prime_factors(a))

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())

sage: a.prime_factors()
[2, 3, 13]
sage: len(a.prime_factors())
edit flag offensive delete link more

answered 2021-08-17 14:54:31 +0200

Max Alekseyev gravatar image

Alternatively one can use omega (or bigomega to count prime factors with multiplicity) functions from GP:

sage: gp.bigomega(234)                                                                                                                                                                                     
edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower


Asked: 2021-08-16 13:43:50 +0200

Seen: 439 times

Last updated: Aug 17 '21