login

Year-end appeal: Please make a donation to the OEIS Foundation to support ongoing development and maintenance of the OEIS. We are now in our 61st year, we have over 378,000 sequences, and we’ve reached 11,000 citations (which often say “discovered thanks to the OEIS”).

Number of partitions of n into a prime and a triangular number.
1

%I #17 Nov 14 2024 10:58:08

%S 0,0,1,2,1,2,2,1,3,1,1,2,2,3,2,1,1,4,2,2,3,1,2,4,2,1,3,1,2,3,2,2,4,2,

%T 3,2,0,2,4,3,2,4,1,3,4,1,2,6,2,2,3,2,3,4,1,1,3,3,4,4,2,1,6,1,3,3,1,3,

%U 6,3,1,4,2,4,6,1,3,4,1,4,3,3,4,5,2,3,4

%N Number of partitions of n into a prime and a triangular number.

%C Indices of zeros: 0 followed by A076768.

%H T. D. Noe, <a href="/A224362/b224362.txt">Table of n, a(n) for n = 0..10000</a>

%F G.f.: (Sum_{i>=0} x^(i*(i+1)/2))*(Sum_{j>=1} x^prime(j)). - _Ilya Gutkovskiy_, Feb 07 2017

%t nn = 13; tri = Table[n*(n + 1)/2, {n, 0, nn}]; pr = Prime[Range[PrimePi[tri[[-1]]]]]; Table[Length[Intersection[pr, n - tri]], {n, 0, tri[[-1]]}] (* _T. D. Noe_, Apr 05 2013 *)

%o (Python)

%o import math

%o primes = [2, 3]

%o def isprime(k):

%o for p in primes:

%o if k%p==0: return 0

%o primes.append(k)

%o return 1

%o def rootTriangular(a):

%o sr = 2**(int(math.log(a,2))+2)

%o while a < sr*(sr+1)//2:

%o sr>>=1

%o b = sr>>1

%o while b:

%o s = sr+b

%o if a >= s*(s+1)//2:

%o sr = s

%o b>>=1

%o return sr

%o for i in range(1<<10):

%o k = 0

%o for p in primes:

%o if i <= p: continue

%o r = rootTriangular(i - p)

%o if r*(r+1)//2 == i-p: k+=1

%o if i>1:

%o if i<=3: k += 1

%o else: k += isprime(i)

%o print(k, end=', ')

%Y Cf. A000040, A000217, A076768, A101182.

%K nonn

%O 0,4

%A _Alex Ratushnyak_, Apr 04 2013