| 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.
| 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)
| 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)
Copyright Sage, 2010. Some rights reserved under creative commons license. Content on this site is licensed under a Creative Commons Attribution Share Alike 3.0 license.