First time here? Check out the FAQ!

Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

The factor method takes an algorithm keyword; have you looked at the documentation?

In your case, since you know that the number of prime factors isn't very large, you could check (if a is your number) whether

p.divides(a)

is true, and while it's true, do a.divide_knowing_divisible_by(p). It might be worth seeing how fast those operations are with your number.

click to hide/show revision 2
No.2 Revision

The factor method takes an algorithm keyword; have you looked at the documentation?

In your case, since you know that the number of prime factors isn't very large, you could check (if a is your number) whether

p.divides(a)

is true, and while it's true, do a.divide_knowing_divisible_by(p). It might be worth seeing how fast those operations are with your number.

Edit:

something like (untested):

b = a
divisors_list = primes_first_n(26) # primes up to 101
divisibility_indices = {p: 0 for p in divisors_list} # keep track of how many times each prime divides a
for p in divisors_list:
    while p.divides(b):
        divisibility_indices[p] += 1
        b = b.divide_knowing_divisible_by(p)
print(divisibility_indices)
click to hide/show revision 3
No.3 Revision

The factor method takes an algorithm keyword; have you looked at the documentation?

In your case, since you know that the number of prime factors isn't very large, you could check (if a is your number) whether

p.divides(a)

is true, and while it's true, do a.divide_knowing_divisible_by(p). It might be worth seeing how fast those operations are with your number.

Edit:

something like (untested):

b = a
divisors_list = primes_first_n(26) # primes up to 101
divisibility_indices 101:
divisors_list = {p: 0 for p in divisors_list} primes_first_n(26)
# keep track of how many times each prime divides a
a:
divisibility_indices = {p: 0 for p in divisors_list}
for p in divisors_list:
    while p.divides(b):
        divisibility_indices[p] += 1
        b = b.divide_knowing_divisible_by(p)
print(divisibility_indices)