Ask Your Question
0

Partitions into perfect kth prime powers

asked 2023-04-30 15:24:12 +0200

brennan gravatar image

I am trying to return partitions of $n$ into perfect $k$th powers of primes, call the function $pp^k(n)$ where $k$ is the $k$th power, so for instance $pp^2(24)=3$ since $24=2^2+2^2+2^2+2^2+2^2+2^2=3^2+3^2+2^2=4^2+2^2+2^2$. I have the code that returns prime partitions of $n$ but I cannot figure out how to tweak it to return perfect $k$th 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!

edit retag flag offensive close merge delete

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 ( 2023-04-30 17:09:53 +0200 )edit

1 Answer

Sort by ยป oldest newest most voted
2

answered 2023-04-30 17:11:27 +0200

updated 2023-04-30 17:11:40 +0200

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

Stats

Asked: 2023-04-30 15:24:12 +0200

Seen: 262 times

Last updated: Apr 30 '23