Loading [MathJax]/jax/output/HTML-CSS/jax.js
Ask Your Question
0

Partitions into perfect kth prime powers

asked 1 year ago

brennan gravatar image

I am trying to return partitions of n into perfect kth powers of primes, call the function ppk(n) where k is the kth power, so for instance pp2(24)=3 since 24=22+22+22+22+22+22=32+32+22=42+22+22. I have the code that returns prime partitions of n but I cannot figure out how to tweak it to return perfect kth powers.

def pp(n):
    return Partitions(n,parts_in=prime_range(n+1)).cardinality:
for n in srange(1,100):
    print(n,pp(n))

Can someone please help. Thank you so much!

Preview: (hide)

Comments

I'm confused: first, 3^2 + 3^2 + 2^2 is not 24, and second, 4 is not a prime, so 4^2 is not the square of a prime. Shouldn't pp^2(24) = 1?

John Palmieri gravatar imageJohn Palmieri ( 1 year ago )

1 Answer

Sort by » oldest newest most voted
2

answered 1 year ago

updated 1 year ago

Just replace prime_range with a list of prime powers:

def ppk(n,k):
    pows = [m**k for m in prime_range(n+1) if m**k < n+1]
    return Partitions(n, parts_in=pows).cardinality()
Preview: (hide)
link

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

Stats

Asked: 1 year ago

Seen: 398 times

Last updated: Apr 30 '23