Ask Your Question
1

Partitions into distinct primes OEIS:A000586

asked 2023-05-26 11:00:05 +0100

brennan gravatar image

Hello, I am trying to return the number of partitions of $n$ into distinct primes, OEIS A000586. I tried copying the python example from the OEIS, changing "primerange" to "Primes" but got an error

def a(n,k=None):
    if k==None: k=n
    if n<1: return int(n==0)
    return sum(a(n-p,p-1) for p in Primes(1,k+1)
for n in srange(1,50):
    print(n,a(n))

I would really appreciate some help. Thank you!

edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted
1

answered 2023-05-26 11:17:38 +0100

FrédéricC gravatar image

Like this

sage: @cached_function
....: def a(n,k=None):
....:     if k is None: k=n
....:     if n<1: return int(n==0)
....:     return sum(a(n-p,p-1) for p in prime_range(k+1))
....: print([a(n) for n in range(1,50)])
edit flag offensive delete link more

Comments

Thank you so much! I see the prime_range now, thanks!!

brennan gravatar imagebrennan ( 2023-05-26 11:46:25 +0100 )edit

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-05-26 11:00:05 +0100

Seen: 96 times

Last updated: May 26 '23